-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Description
There is problem with initializing lastRefillTime to negative periodDurationInNanos. Say periodDurationInNanos is 1 (period 1, time unit nanoseconds), in that case it will initialize lastRefillTime to -1.
Now lets look at the period calculation:
public synchronized long refill()
{
long now = ticker.read(); // [1]
...
long numPeriods = Math.max(0, (now - lastRefillTime) / periodDurationInNanos); // [2]
...
[1] will return a big number (say 1188589593996144), and [2] will simple add 1 to the big number making it 1188589593996145. (See the problem yet). If you divide this by periodDurationInNanos (which was 1 btw). You get huge amount of tokens prebuilt.
Why does not test catch this? MockTicket always starts at 0. But System ticker won't.
rougou
Metadata
Metadata
Assignees
Labels
No labels