-
Notifications
You must be signed in to change notification settings - Fork 279
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
After long inactivity period, available token counter becomes negative #51
Comments
Yes, you properly detected the source of problem. I will release the fix in few days. |
Which version do you use? |
I am using bucket4j-core 2.1.0 and bucket4j-jcache 2.1.0. |
Looks like with your limits bucket will work normally only for 3,6 hours between invokation public static void main(String[] args) {
double d = Long.MAX_VALUE;
System.out.println(d / (700000L * 1_000_000_000L * 3600L));
} . As dirty work-around you can touch the bucket periodically: if (bucket.tryConsume(1)) {
bucket.addTokens(1);
} The fixes will be prepared for branches 2.0, 2.1, 3.0, most likely tommorrow. |
# Conflicts: # README.md # bucket4j-benchmarks/pom.xml # bucket4j-core/pom.xml # bucket4j-jcache/pom.xml # bucket4j-jcache/src/main/java/io/github/bucket4j/grid/jcache/JCacheCommand.java # bucket4j-parent/pom.xml # pom.xml # release-reactor/pom.xml
# Conflicts: # README.md # bucket4j-benchmarks/pom.xml # bucket4j-core/pom.xml # bucket4j-jcache/pom.xml # bucket4j-jcache/src/main/java/io/github/bucket4j/grid/jcache/JCacheCommand.java # bucket4j-parent/pom.xml # pom.xml # release-reactor/pom.xml
# Conflicts: # README.md # bucket4j-benchmarks/pom.xml # bucket4j-core/pom.xml # bucket4j-core/src/main/java/io/github/bucket4j/BucketExceptions.java # bucket4j-core/src/main/java/io/github/bucket4j/Refill.java # bucket4j-jcache/pom.xml # bucket4j-jcache/src/main/java/io/github/bucket4j/grid/jcache/ExecuteProcessor.java # bucket4j-parent/pom.xml # experimental/pom.xml # pom.xml
# Conflicts: # README.md # bucket4j-benchmarks/pom.xml # bucket4j-core/pom.xml # bucket4j-core/src/main/java/io/github/bucket4j/BucketExceptions.java # bucket4j-core/src/main/java/io/github/bucket4j/Refill.java # bucket4j-jcache/pom.xml # bucket4j-jcache/src/main/java/io/github/bucket4j/grid/jcache/ExecuteProcessor.java # bucket4j-parent/pom.xml # experimental/pom.xml # pom.xml
@MichelePaterniti please use 2.1.1(or 3.0.2) version. |
Thanks for the promptness of your fix. |
I noticed that, at least with some bandwidth configuration, when a long time passes between subsequent calls to Bucket.tryConsume(...), the available token counter becomes negative and Bucket.tryConsume(...) return false, while there should be lots of tokens available.
I guess this could be caused by an arithmetic overflow in executing line 136
long divided = refillTokens * durationSinceLastRefillNanos + roundingError;
in private method io.github.bucket4j.BucketState.refill(int, Bandwidth, long, long).
To reproduce the problem, you can use the following test:
The text was updated successfully, but these errors were encountered: