Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http/httptrace: function called after RoundTrip returns an error #16957
The documentation for httptrace says
// Functions may be // called concurrently from different goroutines, starting after the // call to Transport.RoundTrip and ending either when RoundTrip // returns an error, or when the Response.Body is closed.
However, if RoundTrip is canceled or times out before t.dialConn completes, ConnectStart can be called concurrently with code that runs after RoundTrip returns an error.
Here is a sample race found by TSAN:
I'm not sure if this is a documentation bug or a code bug. The only way to implement the documentation faithfully is to either (a) prevent calling hooks after the conditions specified in the doc have been reached, or (b) wait for the background t.dialConn to complete before returning from RoundTrip with an error. The second solution doesn't seem practical. The first solution is doable, but do we really need a strict guarantee in the first place?