Negative or huge Retry-After makes the retry sleep throw IllegalArgumentException

未关闭 适合新手
#239 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

从 httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/B2WebApiHttpClientImpl.java 中的 getRetryAfterSecondsOrNull 开始,然后查看 core/src/main/java/com/backblaze/b2/client/ 中的 B2DefaultRetryPolicy.java 和 B2Sleeper.sleepSeconds。编写一个单元测试来复现问题:让 B2Retryer.doRetry 收到一个可重试的异常,并让 getRetryAfterSecondsOrNull 返回 -1 或 2200000。当超出范围的 Retry-After 值被限制或被拒绝,并且睡眠不再抛出 IllegalArgumentException 时,即完成。

由索引模型根据 Issue 内容生成。

描述

What happens

The Retry-After header is parsed with Integer.parseInt and returned unchanged as the wait time. B2Sleeper.sleepSeconds then computes seconds * 1000 as an int, which is negative for a negative header and overflows for values above about 2.1 million seconds, and Thread.sleep throws an unchecked IllegalArgumentException. The exception escapes the retry loop, although the code comment in B2Retryer says the sleep "won't throw".

Where

httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/B2WebApiHttpClientImpl.java:303-314 (getRetryAfterSecondsOrNull), core/src/main/java/com/backblaze/b2/client/B2DefaultRetryPolicy.java:44-52 (returns the server value unchecked), core/src/main/java/com/backblaze/b2/client/B2Sleeper.java:37-38 (seconds * 1000), called from B2Retryer.java (sleeper.sleepSeconds(waitSeconds)).

Why it matters

Impact: Availability (a retryable error turns into an unexpected runtime exception), loud. Severity: High, because it needs a Retry-After value that is negative or over about 2.1 million seconds from the server (unusual, since the HTTP spec allows only non-negative delays), and there is no workaround besides a custom retry policy.

How to check

Found by reading the code, not reproduced. Read the four places above. A unit test could make B2Retryer.doRetry see a retryable exception whose getRetryAfterSecondsOrNull() returns -1 or 2200000 and observe the exception from Thread.sleep. Clamping the value to a sane range in the retry policy or in B2Sleeper would avoid it.

Version

Seen at v6.5.0. Present on the default branch: present.

主要语言
Java
星标
103
派生
23
平均合并
5 天 8 小时
30 天内合并 PR
3

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Backblaze/b2-sdk-java 的其他 Issue

查看 Backblaze/b2-sdk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。