RateLimiter.tryAcquire blocks when it should not
siddhsql opened this issue · comments
siddhsql commented
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 commented
sorry my mistake