Update utils.py

Prevent exponential_backoff() to crash with an Vverflow Error
This commit is contained in:
Tim Kreuzer
2020-10-12 17:25:25 +02:00
committed by GitHub
parent 8d50554849
commit c97e4d4e2f

View File

@@ -171,7 +171,15 @@ async def exponential_backoff(
# add some random jitter to improve performance
# this prevents overloading any single tornado loop iteration with
# too many things
# Except Overflow Error. Otherwise start_wait * scale will be too big at some point.
try:
if scale == 0:
dt = min(max_wait, remaining))
else:
dt = min(max_wait, remaining, random.uniform(0, start_wait * scale))
except OverflowError:
scale = 0
dt = min(max_wait, remaining)
scale *= scale_factor
await gen.sleep(dt)
raise TimeoutError(fail_message)