Skip to content

Commit 999472b

Browse files
committed
Fix for bucket update
1 parent 369e707 commit 999472b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tb_device_mqtt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ def set_limit(self, rate_limit, percentage=DEFAULT_RATE_LIMIT_PERCENTAGE):
352352

353353
if previous_bucket:
354354
previous_bucket.refill()
355-
used = previous_bucket.capacity - previous_bucket.tokens
356-
new_bucket.tokens = max(0.0, new_capacity - used)
355+
used = max(0.0, previous_bucket.capacity - previous_bucket.tokens)
356+
new_tokens = new_capacity - used
357+
new_bucket.tokens = min(new_capacity, max(0.0, new_tokens))
357358
new_bucket.last_updated = monotonic()
358359
else:
359360
new_bucket.tokens = new_capacity

0 commit comments

Comments
 (0)