google / guava

Google core libraries for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RateLimiter.tryAcquire blocks when it should not

siddhsql opened this issue · comments

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).

sorry my mistake