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

Aberta Para iniciantes
#239 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 3 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
java
Domínio
backend

Direção de pesquisa

Comece por getRetryAfterSecondsOrNull em httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/B2WebApiHttpClientImpl.java e depois por B2DefaultRetryPolicy.java e B2Sleeper.sleepSeconds em core/src/main/java/com/backblaze/b2/client/. Reproduza o problema com um teste unitário que faça B2Retryer.doRetry receber uma exceção repetível e getRetryAfterSecondsOrNull retornar -1 ou 2200000. Está concluído quando os valores de Retry-After fora do intervalo forem limitados ou rejeitados e a pausa não lançar mais IllegalArgumentException.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Java
Estrelas
103
Forks
23
Merge médio
5d 8h
PRs com merge (30d)
3

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de Backblaze/b2-sdk-java

Todas as issues de Backblaze/b2-sdk-java

Issues semelhantes

Mais issues de Java

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.