net/http/httptest: Server.Close mutates http.DefaultTransport #65796
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go version go1.21.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
It seems that the default transport object
http.DefaultTransport
gets mutated by theClose
method ofhttptest.Server
.Here is a test that demonstrates it:
The
TLSClientConfig
field of theDefaultTransport
object isnil
to start with, but then it gets replaced with a non nil instance after the Close method returns. Here is the call chain of the mutation:httptest/Server.Close
invokes theCloseIdleConnections
method of the defaultDefaultTransport
object:go/src/net/http/httptest/server.go
Lines 237 to 242 in cf52e70
go/src/net/http/transport.go
Lines 783 to 784 in cf52e70
TLSClientConfig.NextProtos
gets set:go/src/net/http/h2_bundle.go
Lines 7269 to 7274 in cf52e70
I am not certain if it's common for production code to exercise:
I ran into this issue with unit tests that verify that the
TLSClientConfig
field of a given transport does not get mutated unexpectedly. I can change the test to work around it. But I wanted to bring this to your attention so you can assess whether it can impact production code.The text was updated successfully, but these errors were encountered: