Skip to content

Close response inflater resources on every exit - #336

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/inflater-close-http
Open

Close response inflater resources on every exit#336
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/inflater-close-http

Conversation

@OskarEichler

Copy link
Copy Markdown

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

  • Ruby 4.0.6 through rbenv; existing bundle exec rake test: 201 tests / 914 assertions / zero failures or errors, baseline and isolated patch.
  • 34 focused checks cover gzip/zlib, empty content, fixed-length/chunked/EOF framing, decoded body/length preservation and immediate closure. Failure cases cover invalid compressed data, a finish-time error through the internal inflater wrapper, and a raising destination, preserving the existing exception class.
  • Syntax and git diff --check pass; supplemental Lint scan has the same 25 baseline findings.
  • No test/spec files were added or modified, per this contribution's no-new-tests constraint; focused reproductions ran externally.

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.

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.

1 participant