Repository navigation
Close GZIPInputStream wrapper in JdkHttpSender#toHttpResponse - #9080
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
TimurRakhmatullin86 wants to merge 1 commit into
TimurRakhmatullin86 wants to merge 1 commit into
Conversation
The gzip decompression path wraps the response body in a GZIPInputStream but keeps only the underlying rawIs in the try-with-resources. Closing rawIs does not close the wrapper, so its native Inflater is never released. Every gzip response leaks one Inflater — and the same leak fires on IO errors while reading, which already use this path. Include the wrapper in the try-with-resources. Closing the gzip stream also closes rawIs, so the second declaration in the resource list is harmless when decompression is off. Added JdkHttpSenderTest#sendInternal_gzipResponse_closesGzipWrapper: the mocked body stream tracks close() calls. Without the fix the count is 1 (outer try-with-resources only). With the fix the gzip wrapper forwards its own close to the body, so the count is >= 2.
Pull request dashboard statusWaiting on reviewers · refreshed 2026-11-30 16:52 UTC Review the latest changes. Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9080 +/- ##
============================================
- Coverage 90.52% 90.51% -0.01%
Complexity 11243 11243
============================================
Files 1039 1039
Lines 30678 30678
Branches 4015 4015
============================================
- Hits 27772 27769 -3
- Misses 1928 1929 +1
- Partials 978 980 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Summary
JdkHttpSender#toHttpResponsewraps the response body in aGZIPInputStreamfor gzip-encoded responses but only includes the underlyingrawIsin the try-with-resources block. ClosingrawIsdoes not close the wrapper, so the gzip stream's nativeInflateris never released — oneInflaterleaks on every gzip response. The same leak fires on IO errors while reading the body (same code path) and onResponseBodyTooLargeException(thrown after the try block closesrawIsbut after the wrapper was created).Before:
After:
Closing the gzip stream also closes
rawIs, so the second declaration is harmless whendecompressis false (the two resources point at the same stream).Test
JdkHttpSenderTest#sendInternal_gzipResponse_closesGzipWrapper: feeds a valid gzip payload through a mocked HTTP response whose body stream tracksclose()calls.rawIsonce; the gzip wrapper is never closed — count == 1.rawIsas part of its ownclose(), and the outer try-with-resources closes it a second time — count >= 2.The assertion
isGreaterThanOrEqualTo(2)captures that the gzip wrapper'sclose()was called. I verified the test fails with count == 1 against the previous version of the file.