Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RateLimiter.tryAcquire blocks when it should not #7247

Closed
siddhsql opened this issue Jun 4, 2024 · 1 comment
Closed

RateLimiter.tryAcquire blocks when it should not #7247

siddhsql opened this issue Jun 4, 2024 · 1 comment
Labels
type=defect Bug, not working as expected

Comments

@siddhsql
Copy link

siddhsql commented Jun 4, 2024

Description

according to documentation the tryAcquire method is not supposed to block but in my testing it does exactly the opposite.

Example

public RateLimiterService rateLimiter() {
    return new RateLimiterService(RateLimiter.create(config.maximumQueriesPerSecond));
  }

@RequiredArgsConstructor
public class RateLimiterService {
  private final RateLimiter rateLimiter;

  public void check() {
    if (!this.rateLimiter.tryAcquire()) {
      throw new QuotaExceededException();
    }
  }
}

in controller class:

this.rateLimiter.check();

bash script:

#!/bin/bash
while true
do
	curl http://localhost:8080/query/something
done


### Expected Behavior

quotaexceededexception

### Actual Behavior

requests are throttled instead of exception

### Packages

_No response_

### Platforms

_No response_

### Checklist

- [X] I agree to follow the [code of conduct](https://github.com/google/.github/blob/master/CODE_OF_CONDUCT.md).
@siddhsql siddhsql added the type=defect Bug, not working as expected label Jun 4, 2024
@siddhsql
Copy link
Author

siddhsql commented Jun 4, 2024

sorry my mistake

@siddhsql siddhsql closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

1 participant