Output stream close() leaks the file handle if flush or sync fails

Aperta Adatta ai principianti
#234 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à
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Leggi prima il metodo close() in core/src/main/java/com/backblaze/b2/util/B2FlushAndSyncFileOnCloseOutputStream.java (righe 42-46), che chiama in sequenza out.flush(), out.getFD().sync() e out.close(). Poi racchiudi le chiamate di flush e sync in modo che lo stream sottostante venga chiuso anche quando lanciano un'eccezione. È fatto quando il file descriptor viene chiuso in ogni percorso e la IOException originale continua a essere propagata.

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

Descrizione

What happens

If close() is called on the stream and the flush or getFD().sync() call throws an IOException, the line that closes the underlying FileOutputStream is never reached. The caller gets the exception but the file descriptor stays open until garbage collection.

Where

core/src/main/java/com/backblaze/b2/util/B2FlushAndSyncFileOnCloseOutputStream.java:42-46, method close(): out.flush(); out.getFD().sync(); out.close(); with no try/finally.

Why it matters

Impact: Left behind (an open file handle), loud (the IOException is thrown). Severity: Medium, because it only happens in an unusual condition (an fsync or disk I/O error) and the handle is eventually released by finalization.

How to check

Found by reading the code, not reproduced. Read close(): if flush() or sync() throws, out.close() is skipped. A try/finally (or try-with-resources) around the first two calls would close the stream in every case.

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.