Java compression codecs do not release compressed ArrowBuf in decompress, causing allocator leaks
- 主要言語
- Java
- スター
- 94
- フォーク
- 152
- 平均マージ
- 3日 16時間
- マージ済み PR(30日)
- 11
説明
### 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:
### 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.
コントリビューションガイド
調査の方向性
loadFieldBuffers、デコンプレッションループ、ownBuffersを含む圧縮codecのデコンプレッションパスを特定します。既存のtry-finallyクリーンアップの下にループを移動し、その後、先行するバッファのデコンプレッション後に失敗した場合でもBufferAllocatorの割り当て済みメモリがゼロになり、成功パスではフィールドベクターにバッファが引き続き保持されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- data
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100