Repository navigation
Keep Transport dials from writing request state (v1 branch) - #387
Merged
Merged
Conversation
gauthamw-stripe
approved these changes
Nov 25, 2026
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.Logger and the decision's ResolvedAddr and Reason while the request goroutine still used them, and the race detector reported it. A Transport dial now hands its log fields back through a locked value, and the request keeps them only if the dial finished during RoundTrip. Its re-resolved address stays local. A CONNECT dial runs on the request goroutine, so it still writes the logger and records the re-resolved address and reason in the decision, which hooks such as AcceptResponseHandler read after the dial. Only tracked CONNECT and MITM connections build an enriched logger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shubh-stripe
force-pushed
the
shubh/v1-dial-races
branch
from
November 25, 2026 14:43
0485925 to
1c0043e
Compare
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.
This fixes #383 on the
v1branch. The same fix formasteris in #388.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.Loggerand the decision'sResolvedAddrandReasonwhile the request goroutine still used them.A Transport dial now starts from a copy of the request logger, taken before
RoundTrip, and hands its log fields back through a locked value. The request keeps those fields only if the dial finished duringRoundTrip. A CONNECT dial runs on the request goroutine, so it still writessctx.Loggerdirectly.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_*_addrfields appear only when the dial finished duringRoundTrip.Test plan
I tested this with a race test that this PR leaves out. It is in the branch history at 1b66786. The test 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.v1without the fix, both cases reportDATA RACEbetween the dialer's write tosctx.LoggerandrejectResponse.-race.🤖 Generated with Claude Code