List iterators lose an item when loading the next page fails

Aberta Para iniciantes
#240 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
68/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
java
Domínio
backend

Direção de pesquisa

Comece em next() em core/src/main/java/com/backblaze/b2/client/B2ListFilesIterableBase.java (por volta das linhas 43-58), onde currentIndex é incrementado antes que advanceIfNeeded() possa lançar uma exceção; o mesmo padrão aparece em B2ListPartsIterableBase.java por volta das linhas 30-45. Escreva um teste com um cliente simulado que falhe ao carregar a segunda página e, depois de capturar a exceção, chame next() novamente para confirmar que o item se perde. Está concluído quando o item é retornado ou tentado novamente corretamente e o teste passa, para ambos os iteradores.

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

Descrição

What happens

In next(), the iterator moves past the current item and then loads the next page if the current page is used up. If that page load fails, B2RuntimeException is thrown from next() and the item that was just taken is not returned. A caller that catches the exception and continues will not see that item, and the next next() call fails with an IllegalStateException instead of retrying the page.

Where

core/src/main/java/com/backblaze/b2/client/B2ListFilesIterableBase.java:43-58 (next() at about :50 increments currentIndex, then calls advanceIfNeeded()); the same pattern is in core/src/main/java/com/backblaze/b2/client/B2ListPartsIterableBase.java:30-45.

Why it matters

Impact: Wrong request or result (a listing silently misses an item for a caller that continues after the error), loud for the failed call. Severity: Medium, because it needs a page load that fails after retries and a caller that catches the error and keeps iterating (unusual), and a caller that stops on the first error is not affected.

How to check

Found by reading the code, not reproduced. Read next(): the value is read and currentIndex incremented before advanceIfNeeded() can throw. A test with a mocked client that fails on the second page load, and a caller that catches the exception and calls next() again, would show the missing item. Advancing lazily in hasNext() or returning the item before advancing 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.