Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: TestRetryRequestsOnError/NothingWrittenGetBody is flaky #25366

Closed
eliasnaur opened this issue May 13, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@eliasnaur
Copy link
Contributor

commented May 13, 2018

https://build.golang.org/log/105ed515d4bc46f62bf7454d6cab5f602f3f8a04:

--- FAIL: TestRetryRequestsOnError (0.01s)
    --- FAIL: TestRetryRequestsOnError/NothingWrittenGetBody (0.00s)
    	transport_test.go:2886: i=1: Do = Post http://fake.golang: read tcp 127.0.0.1:55575->127.0.0.1:55574: use of closed network connection
FAIL
FAIL	net/http	93.837s

@eliasnaur eliasnaur changed the title net/http: TestRetryRequestsOnError/NothingWrittenGetBody flaky on darwin/arm64 net/http: TestRetryRequestsOnError/NothingWrittenGetBody is flaky May 14, 2018

@eliasnaur

This comment has been minimized.

Copy link
Contributor Author

commented May 14, 2018

This seems like a real bug in the logic for determining when a request can be retried. I can reproduce the failure on the iDevice with

$ GOARCH=arm64 GOOS=darwin go test -short -run "TestRetryRequestsOnError/NothingWrittenGetBody" -count=1000 net/http

But I can force the failure to be 100% reproducible on macOS with the following change:

diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index cce88ca239..c76f268782 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -1822,7 +1822,9 @@ func (pc *persistConn) writeLoop() {
                                if pc.nwrite == startBytesWritten {
                                        err = nothingWrittenError{err}
                                }
+                               pc.conn.Close()
                        }
+                       time.Sleep(time.Second)
                        pc.writeErrCh <- err // to the body reader, which might recycle us
                        wr.ch <- err         // to the roundTrip function
                        if err != nil {

Where the extra pc.conn.Close() and sleep simulates that the server closes the connection before the error from writeLoop reaches the roundTrip function.

I reproduced it with the following on a darwin/amd64 macOS machine:

$ go test -short -run "TestRetryRequestsOnError/NothingWrittenGetBody" -count=1 net/http
--- FAIL: TestRetryRequestsOnError (0.06s)
    --- FAIL: TestRetryRequestsOnError/NothingWrittenGetBody (0.06s)
    	transport_test.go:2886: i=1: Do = Post http://fake.golang: read tcp 127.0.0.1:51567->127.0.0.1:51565: use of closed network connection
FAIL
FAIL	net/http	0.077s

CC @bradfitz and @glasser (who wrote TestRetryRequestsOnError/NothingWrittenGetBody).

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone May 31, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Jul 23, 2018

Change https://golang.org/cl/125555 mentions this issue: net/http: deflake TestRetryRequestsOnError

@gopherbot gopherbot closed this in 416676f Jul 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.