Repository navigation
Keep Transport dials from writing request state - #388
Merged
Merged
Conversation
net/http's Transport dials on its own goroutine, and it can finish a dial after RoundTrip returns. That happens when the client cancels, or when another pooled connection serves the request first. dialContext then wrote sctx.dialAttrs and the decision's ResolvedAddr and Reason, and read the request logger, while the request goroutine still used them. A Transport dial now starts from a copy of the request logger and hands its attributes back through a locked value. The request keeps them only if the dial finished during RoundTrip. A re-resolved address stays local to dialContext, so the logged decision reason stays the ACL reason, as it already was for CONNECT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Committed-By-Agent: claude
A CONNECT dial runs on the request goroutine, so writing the re-resolved address and reason to the decision never raced. Hooks that run after the dial, such as AcceptResponseHandler, read Decision.ResolvedAddr and expect the address that was dialed, for example an upstream proxy. Only a Transport dial keeps its result local now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Committed-By-Agent: claude
gauthamw-stripe
approved these changes
Nov 25, 2026
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.
Fixes #383. The same fix for the
v1branch is in #387.For plain HTTP requests and MITM inner requests, net/http's Transport dials on its own goroutine. It can finish the dial after
RoundTripreturns, for example when the client cancels or when another pooled connection serves the request first.dialContextthen wrotesctx.dialAttrsand the decision'sResolvedAddrandReason, and it read the request logger, while the request goroutine still used them.A Transport dial now starts from a copy of the request logger, taken before
RoundTrip, and hands its attributes back through a locked value. The request keeps them only if the dial finished duringRoundTrip. A CONNECT dial runs on the request goroutine, so it still writessctx.dialAttrsdirectly.Two log changes come with this:
decision_reasonkeeps the ACL reason, andDecision.ResolvedAddrkeeps the address from the ACL check. They used to change to the dialer's result. A CONNECT dial still records the re-resolved address and reason in the decision as before, for example the address of an upstream proxy, because it runs on the request goroutine.conn_establish_time_msand theoutbound_*_addrattributes appear only when the dial finished duringRoundTrip.A custom resolver still gets the live
SmokescreenContextwhen a Transport dial resolves an address again. The resolver docs already say to treat it as read-only and to not keep it, so this PR leaves that as it is.Test plan
I tested this with a race test that this PR leaves out. It cancels a plain HTTP request while net/http holds a dial for it. It holds the dial once inside the configured dialer and once before
dialContextstarts, and it orders the steps with channels instead of sleeps.masterwithout the fix, both cases reportDATA RACEbetween the dialer's write tosctx.dialAttrsand the reads indiagnosticLoggerandlogProxy.-race.🤖 Generated with Claude Code