DeflateDecompressor: fix inflater memory leak (#1137)#1140
Merged
Conversation
* fix: DeflateDecompressor inflater memory leak Motivation: DeflateDecompressor allocates an Inflater per stream but never explicitly releases its native memory. Under GCs with relaxed off-heap reclamation (e.g. ZGC), repeated request decompression can accumulate unreclaimed native buffers and eventually OOM. Modification: - Add createInflater(noWrap) factory method to DeflateDecompressor to allow test injection of a custom Inflater - Track the current inflater in a var within createLogic - Add idempotent cleanupInflater() that calls inflater.end() - Override postStop() to call cleanupInflater(), covering normal completion, failure, and cancellation - Add focused tests in DeflateSpec verifying the inflater is released on successful decode, early cancellation, and truncation Result: The Inflater's native memory is reclaimed promptly when the stage terminates, regardless of termination path. Tests: - Not run - sbt/builds skipped per user request to conserve credits References: Refs apache#1134 * Update DeflateSpec.scala * close existing inflater * fix: await inflater.end() before asserting in cancellation test The Sink.ignore future completes when take(1) sends Complete downstream, but the Cancel signal that triggers postStop() (and thus end()) is a separate actor message dispatched afterwards. This means awaitResult can return before end() has been called, yielding endCalls = 0. Add a CountDownLatch to TrackingInflater that is counted down inside end(), and call inflater.awaitEnd() after awaitResult() in the cancellation test to eliminate the race. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
He-Pin
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cherry pick 418e760 (#1137)