go: net/http: TestRetryRequestsOnError failures with "use of closed network connection"
From https://storage.googleapis.com/go-build-log/c7862f5a/linux-amd64-race_4ed6f3c3.log
--- FAIL: TestRetryRequestsOnError (0.02s)
--- FAIL: TestRetryRequestsOnError/NothingWrittenGetBody (0.00s)
transport_test.go:3116: i=1: Do = Post http://fake.golang: read tcp 127.0.0.1:52650->127.0.0.1:42017: use of closed network connection; log:
Dial
Write("POST / HTTP/1.1\r\nHost: fake.golang\r\nUser-Agent: Go-http-client/1.1\r\nContent-Length: 4\r\nAccept-Encoding: gzip\r\n\r\nfoo\n")
Handler
intentional write failure
2019/03/19 21:17:09 http: TLS handshake error from 127.0.0.1:38418: write tcp 127.0.0.1:43483->127.0.0.1:38418: use of closed network connection
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 33 (28 by maintainers)
When a write fails,
persistConn.roundTrip
can learn of it in one of three ways:writeErrCh
: https://go.googlesource.com/go/+/refs/tags/go1.17.6/src/net/http/transport.go#2615pcClosed
, after the write loop closes the conn: https://go.googlesource.com/go/+/refs/tags/go1.17.6/src/net/http/transport.go#2631resc
, after the write loop closes the conn and the read loop exits: https://go.googlesource.com/go/+/refs/tags/go1.17.6/src/net/http/transport.go#2645This test failure occurs in the last case. It’s uncommon, because quite a lot needs to happen between the write loop signaling
writeErrCh
androundTrip
reading from it: ThepersistConn
is closed, the read loop reads an error, the read loop sends onresc
, androundTrip
reads fromresc
.