Repository navigation
Expose the session's accepted conn to stream handlers - #17
Merged
Merged
Conversation
Each CONNECT stream's ctx now carries the connection accepted from the listener, beneath TLS, via ServeConnOpts.Context. SessionConnFromContext returns it, so a handler can read socket state such as TCP_INFO that the HTTP/2 stream cannot reach. The base ctx stays Background, which is what ServeConn uses when Context is nil, so stream lifetimes are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EpEDo42eAorMVquPHGmAT6
There was a problem hiding this comment.
🟢 Approval recommended
The focused change preserves existing lifetimes, includes integration coverage, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Exposes the accepted session connection to HTTP/2 stream handlers so downstream probe logic can inspect socket delivery state.
Changes:
- Adds
SessionConnFromContextand documents shared-connection restrictions. - Propagates the connection through HTTP/2 request contexts without changing stream lifetimes.
- Tests that two streams receive the same underlying TCP connection.
| File | Description |
|---|---|
| server.go | Adds the context accessor and passes the accepted connection to handlers. |
| integration_test.go | Verifies connection type, remote address, and sharing across streams. |
Review effort: Balanced
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.
Why
lantern-box answers bandit probes on the proxy and judges whether the response reached the client from the kernel's TCP state (
TCP_INFObytes acked,SIOCOUTQ). On samizdat the probe's conn is an HTTP/2 stream with no path back to the socket, so every samizdat probe reportsunknown. The API scoresunknownas a success, so samizdat arms never take a stall penalty while plain-TCP arms do. Samizdat and QUIC (hysteria2) are the two largest sources ofunknownverdicts in the fleet, at roughly 95k each per hour.getlantern/lantern-box#368 already handles the same problem for sing-mux streams by judging delivery on the shared session socket. This PR gives samizdat streams the same access.
What
serveH2now passeshttp2.ServeConnOpts.Context, carrying the connection accepted from the listener (beneath TLS). Every CONNECT stream'sr.Context()inherits it.SessionConnFromContext(ctx) (net.Conn, bool)returns it to theHandler. The doc comment states the contract: the conn is shared by every stream of the session, so handlers must not close it, write to it, or set its deadlines.context.Background(), which is whatServeConnuses whenContextis nil, so stream lifetimes don't change.x/net/http2API. There is no fork patch.lantern-box will copy this conn into the ctx key the probe responder already reads (
mux.ContextWithSessionConn), so the responder itself needs no change. That's a follow-up PR once this merges.Not included: making
serverStreamConn.SetWriteDeadlinereal. In x/net, an expired write deadline resets the whole stream, which would change behaviour for all samizdat traffic. The probe responder already abandons a stuck write after a bounded grace period.Tests
TestIntegrationSessionConnInContextopens two streams over one client session and asserts that each handler gets:*net.TCPConnfrom the ctx;It fails without the
ServeConnOpts.Contextchange ("no session conn in handler ctx") and passes 10/10 under-race. The full suite passes withgo test -race ./....Pre-PR review (local Codex gate)
CODEX GATE: verdict=approve critical=0 important=0 minor=0 reviewed=6approve🤖 Generated with Claude Code
https://claude.ai/code/session_01EpEDo42eAorMVquPHGmAT6
Summary by CodeRabbit