tokenBucket: incorrect count of issued when refill
rschio opened this issue · 1 comments
rschio commented
Lines 66 to 79 in d5d1ad1
A token can be issued between line 68 and 69 and then it will lead to a incorrect issued count and decrease the bucket real capacity.
Example:
refill() and Ask() executes concurrently then:
line 68 executes
line 77 and 78 executes
line 69 and 70 executes
Solution:
issued := atomic.SwapInt32(&tb.issued, 0)