List iterators lose an item when loading the next page fails

Aperta Adatta ai principianti
#240 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Inizia da next() in core/src/main/java/com/backblaze/b2/client/B2ListFilesIterableBase.java (circa righe 43-58), dove currentIndex viene incrementato prima che advanceIfNeeded() possa lanciare un'eccezione; lo stesso schema compare in B2ListPartsIterableBase.java circa alle righe 30-45. Scrivi un test con un client simulato che fallisce al caricamento della seconda pagina, poi richiama next() dopo aver catturato l'eccezione per verificare che l'elemento venga perso. È completato quando l'elemento viene restituito o ritentato correttamente e il test passa, per entrambi gli iteratori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
103
Fork
23
Merge medio
5g 8h
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Backblaze/b2-sdk-java

Tutte le issue di Backblaze/b2-sdk-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.