Retry-After 返回 0 秒

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 Retry-After: 19
  • we wait 19 seconds, then try again:
    —> We get a 429 again, with Retry-After: 0

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?

4 个赞

Probably, should be an easy fix. Another starter task @erlend_sh?

2 个赞

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.

4 个赞

我正在处理这个 bug,并将于明天提交拉取请求。

1 个赞

事实证明,问题并不出在 Lua 脚本的舍入上。Lua 脚本接收到的已经是舍入后的值。

此外,这根本不是舍入问题。即使使用未舍入的秒数,仍然有可能收到带有 Retry-After: 0 的 429 响应。

以下是针对主要问题的修复方案:

以下是针对偶尔会导致相同错误的额外问题的修复方案:

3 个赞