Skip to content

DeflateDecompressor: fix inflater memory leak (#1137)#1140

Merged
pjfanning merged 1 commit into
apache:1.4.xfrom
pjfanning:deflate-1.4
Jul 8, 2026
Merged

DeflateDecompressor: fix inflater memory leak (#1137)#1140
pjfanning merged 1 commit into
apache:1.4.xfrom
pjfanning:deflate-1.4

Conversation

@pjfanning

Copy link
Copy Markdown
Member

cherry pick 418e760 (#1137)

* 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>
@pjfanning pjfanning added this to the 1.4.0 milestone Jul 7, 2026
@pjfanning pjfanning merged commit c23bad5 into apache:1.4.x Jul 8, 2026
10 checks passed
@pjfanning pjfanning deleted the deflate-1.4 branch July 8, 2026 08:33
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.

2 participants