udoprog / leaky-bucket

A token-based rate limiter based on the leaky bucket algorithm.
Apache License 2.0
93 stars 10 forks source link

Idle bucket should not overflow #30

Closed udoprog closed 6 months ago

udoprog commented 6 months ago

This fixes an issue where if a sufficiently period between two acquire's happens, any number of tokens can be acquired from the bucket.

This changes the logic to work in according with the principle that the token bucket can only be filled up to a certain amount. So if an acquire happens after a long period of time, we will still limit the number of tokens available to that task.