When we retry after a 429, we get another 429.
I suspect a round-down issue.
In our scenario:
- we do requests, and eventually get a
429 Too Many Request with
- we wait 19 seconds, then try again:
—> We get a
429 again, with
Now, can it be the actual values were 19.4 and 0.4 for example and they were rounded down for the Retry-After in the headers?
Probably, should be an easy fix. Another starter task @erlend_sh?
I’m not entirely sure where this is happening, but I suspect it has to do with use of Lua’s
tonumber() in rate_limiter.rb—quoth Redis’ EVAL documentation:
Lua has a single numerical type, Lua numbers. There is no distinction between integers and floats. So we always convert Lua numbers into integer replies, removing the decimal part of the number if any.
I’m taking care of this bug and going to submit a pull-request tomorrow.
It turned out that it wasn’t a problem with rounding in Lua script. Lua script gets already rounded values.
Moreover, it’s not a problem with rounding at all. Unrounded seconds might be used, and it would be possible to receive a 429 response with
Retry-After: 0 anyway.
Here is the fix for the main problem:
And here is the fix for an additional problem that can occasionally cause the same error: