backoff
backoff copied to clipboard
Fix some issues around max_time in _next_wait
Added some code & tests around max_time logic of _next_wait.
main motivation here is that I've observed an Overflow in the wait loop;
Without the initial short-circuit before the call to wait.send, the wait function is guaranteed to be called (needlessly). Also it appears that the returned wait time can be negative (if elapsed time is greater than max_time).
When you combine the two, the wait.send function could increase the magnitude of the negative time (e.g. by multiplying or power-ing it) to bigger and bigger magnitudes (in reality it will be getting more negative, and thus smaller, so the min function will keep returning it).
Eventually the size of the number can exceed max range (-2147483648?), and thus we get the OverflowError.
I forked the library as https://github.com/Kirusi/improved_backoff. The issue with _next_wait
is addressed there, albeit in a slightly different way. If you depend on properly working max_time
feel free to use it.
@Kirusi Thanks, I'll have a look at that. TBH I'd been meaning to get back to this with test cases demonstrating the issue, so I'll make a note of that.