apache / apache/arrow-java

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

Offen
#1,037 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Type: bug
Vorherrschende Sprache
Java
Sterne
94
Forks
152
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
11

Beschreibung

### 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Den Dekompressionspfad des Kompressionscodecs finden, der loadFieldBuffers, die Dekompressionsschleife und ownBuffers enthält. Die Schleife unter die vorhandene try-finally-Bereinigung verschieben und anschließend überprüfen, dass ein Fehler nach der Dekompression früherer Puffer den BufferAllocator bei null zugewiesenem Speicher belässt, während der Erfolgspfad weiterhin Puffer im Feldvektor behält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
data
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.