Skip to content

Transfer proxy tunnel socket ownership - #247

Open
samuel-williams-shopify wants to merge 4 commits into
mainfrom
explicit-proxy-tunnel-ownership
Open

Transfer proxy tunnel socket ownership#247
samuel-williams-shopify wants to merge 4 commits into
mainfrom
explicit-proxy-tunnel-ownership

Conversation

@samuel-williams-shopify

@samuel-williams-shopify samuel-williams-shopify commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make Async::HTTP::Body::Pipe#to_io a documented, one-shot transfer of the tail socket
  • return an ordinary socket from Proxy#connect, with no callback or reference into its originating Async context
  • explicitly close both the socket and forwarding pipe when Proxy#connect is used with a block
  • verify that a second to_io call fails explicitly and that closure from another thread is observed through the socket pair
  • document the lifecycle change in the unreleased notes

Proxy#connect returns an IO which may outlive or leave the thread or execution context that created it. Calling back into the pipe from Socket#close would therefore share mutable Async state across contexts, and Ruby IO autoclose does not invoke a Ruby-level close override.

Body::Pipe#to_io now transfers ownership and clears the pipe reference to the returned socket. It may only be called once; subsequent calls raise IOError. The caller exclusively owns that IO, so it can close normally or be automatically collected. The forwarding tasks observe EOF and write failures through the Unix socket pair and close their respective HTTP bodies. Cleanup is consequently eventual rather than an unsafe synchronous callback into the originating task.

The block form retains deterministic scoped cleanup because the proxy still owns both values for the duration of the block.

This complements #244: transient CONNECT tasks do not keep the creator alive, while the returned socket is not retained by those tasks.

Verification

  • bundle exec sus test/async/http/body/pipe.rb test/async/http/proxy.rb (34 passed)
  • bundle exec bake test (259 passed, 3 skipped)
  • bundle exec rubocop (135 files, no offenses)
  • COVERAGE=PartialSummary BUNDLE_WITH=maintenance bundle exec bake decode:index:coverage lib (293/293)

Assisted-By: devx/618580b0-d55f-4c2e-95b6-87e648f60543
Assisted-By: devx/618580b0-d55f-4c2e-95b6-87e648f60543
@samuel-williams-shopify samuel-williams-shopify changed the title Give pipe sockets explicit ownership Transfer proxy tunnel socket ownership Aug 31, 2026
Assisted-By: devx/618580b0-d55f-4c2e-95b6-87e648f60543
Assisted-By: devx/618580b0-d55f-4c2e-95b6-87e648f60543
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