Skip to content

[client]Fix memory leak if oom when decompress data.#2647

Merged
loserwang1024 merged 3 commits intoapache:mainfrom
loserwang1024:fix-memory-leak
Feb 26, 2026
Merged

[client]Fix memory leak if oom when decompress data.#2647
loserwang1024 merged 3 commits intoapache:mainfrom
loserwang1024:fix-memory-leak

Conversation

@loserwang1024
Copy link
Contributor

Purpose

Linked issue: close #2646

Brief change log

Tests

API and Format

Documentation

@loserwang1024
Copy link
Contributor Author

@platinumhamburg @wuchong , CC

// vectorSchemaRootMap,
// for example temporary buffers left behind when an OOM occurs during decompression
// (see https://github.com/apache/fluss/issues/2646).
bufferAllocator.releaseBytes(bufferAllocator.getAllocatedMemory());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The approach is consistent with RecordAccumulator.close().

One concern: releaseBytes() only adjusts the allocator's accounting but doesn't actually free the underlying direct memory - those buffers will
remain until GC. This fix prevents the IllegalStateException on close, which is good for avoiding cascading failures, but the actual memory may still
leak temporarily.

For a more robust solution, consider adding try-finally in ZstdArrowCompressionCodec.doDecompress() to ensure temp buffers are released on failure.
But the current fix is acceptable as a defensive measure.

Copy link
Contributor Author

@loserwang1024 loserwang1024 Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZstdArrowCompressionCodec.doDecompress() cannot do this, because as i mention in issue:When fail in ZstdArrowCompressionCodec.doDecompress() , we need to release buffers in in org.apache.arrow.vector.VectorLoader#loadBuffers which is the code of arrow.
image

Copy link
Contributor Author

@loserwang1024 loserwang1024 Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@platinumhamburg , I modified this PR and add a patched version of Arrow's {@code VectorLoader} to fix this problem. Detail see VectorLoaderTest

Copy link
Contributor

@platinumhamburg platinumhamburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work identifying and fixing this Arrow buffer leak! I verified that the upstream Arrow-Java main branch
still has this bug in VectorLoader.loadBuffers() — the decompression loop sits outside the try block, and
buf.close() only runs on the success path. So this patch is definitely necessary.

The fix logic is correct: moving the decompression loop inside the try block and releasing buffers in the finally
clause properly handles both the success path (loadFieldBuffers retains +1, finally close -1) and the error path
(finally close frees all already-decompressed buffers).

Below are only one suggestion to improve maintainability.

Copy link
Contributor

@platinumhamburg platinumhamburg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@loserwang1024 loserwang1024 merged commit 9ec7152 into apache:main Feb 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bufferAllocator of LogRecordReadContext will leak if oom when decompress data.

2 participants