apache / apache/arrow-java

Java compression codecs do not release compressed ArrowBuf in decompress, causing allocator leaks

Aperta
#1,037 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Type: bug
Lingua principale
Java
Stelle
94
Fork
152
Merge medio
3g 16h
PR unite (30g)
11

Descrizione

### bug
When using Arrow Java’s compression codecs (e.g. ZSTD) from downstream projects, we observed that an OutOfMemoryError: Direct buffer memory during decompression can leave the associated BufferAllocator in a leaked state (its allocated memory never returns to zero after the failing operation).

In our case this surfaced in Apache Fluss (see [apache/fluss#2646](https://github.com/apache/fluss/issues/2646)), but after investigation the root cause appears to be in Arrow Java’s compression codec implementation:

Image

### version
18.3.0

### Solve
In the original Arrow implementation, the decompression loop runs outside the try-finally block that guards loadFieldBuffers. This means if decompression succeeds for the first N buffers of a field but fails on the (N+1)-th buffer, the already-decompressed buffers in ownBuffers are never closed, leaking Direct Memory.

To fix it, move the decompression loop inside the try block so that the finally clause always closes every buffer in ownBuffers, regardless of whether the load succeeds or fails:
* Success path: loadFieldBuffers retains each buffer (ref count +1), then the finally close decrements it back (ref count -1). The field vector still holds the buffer.
* Error path: The finally close decrements each already-decompressed buffer's ref count to 0, immediately freeing the Direct Memory.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Individuare il percorso di decompressione del codec di compressione che contiene loadFieldBuffers, il ciclo di decompressione e ownBuffers. Spostare il ciclo sotto la pulizia try-finally esistente, quindi verificare che un errore dopo la decompressione dei buffer precedenti lasci BufferAllocator con zero memoria allocata, mentre il percorso di successo conservi ancora i buffer nel vettore dei campi.

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

Valutazione

Stack tecnologico
java
Ambito
data
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.