Close response inflater resources on every exit - #336
Open
OskarEichler wants to merge 1 commit into
Open
Conversation
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
Close the response inflater in an ensure block after finishing and reading the inflated-byte count. This releases the zlib stream resources on success and failure instead of leaving cleanup to GC, while retaining existing response-length and exception behavior.
Reproduction
Keep references to the Zlib::Inflate objects created by Net::HTTPResponse::Inflater, then read a complete gzip response. Before this change,
closed?remains false after the response finishes. It also remains false after an invalid compressed stream or a failing destination. Afterward, the streams are immediately closed in all these paths, even while references remain alive.Zlib::ZStream#close provides explicit stream cleanup; calling finish alone does not close it.
Verification
bundle exec rake test: 201 tests / 914 assertions / zero failures or errors, baseline and isolated patch.git diff --checkpass; supplemental Lint scan has the same 25 baseline findings.Compatibility and limitations
No public API/dependency/Ruby-requirement change. The internal wrapper gains close; finish and bytes_inflated retain their behavior and are called before close. No claim of measured production RSS improvement: verification observes explicit closure with retained references. This does not change existing truncated-response/error-suppression policies. Other Ruby/OS combinations and optional external OpenSSL checks were not run.