Skip to content

Commit 561a507

Browse files
Bryan C. Millsgopherbot
authored andcommitted
net/http: avoid leaking goroutines when TestServerGracefulClose retries
If the call to ReadString returns an error, the closure in testServerGracefulClose will return an error and retry the test with a longer timeout. If that happens, we need to wait for the conn.Write goroutine to complete so that we don't leak connections across tests. Updates #57084. Fixes #62643. Change-Id: Ia86c1bbd0a5e5d0aeccf4dfeb994c19d1fb10b00 Reviewed-on: https://go-review.googlesource.com/c/go/+/528398 Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 08cdfd0 commit 561a507

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/net/http/serve_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,12 +3135,19 @@ func testServerGracefulClose(t *testing.T, mode testMode) {
31353135
if err != nil {
31363136
return err
31373137
}
3138-
defer conn.Close()
31393138
writeErr := make(chan error)
31403139
go func() {
31413140
_, err := conn.Write(req)
31423141
writeErr <- err
31433142
}()
3143+
defer func() {
3144+
conn.Close()
3145+
// Wait for write to finish. This is a broken pipe on both
3146+
// Darwin and Linux, but checking this isn't the point of
3147+
// the test.
3148+
<-writeErr
3149+
}()
3150+
31443151
br := bufio.NewReader(conn)
31453152
lineNum := 0
31463153
for {
@@ -3156,10 +3163,6 @@ func testServerGracefulClose(t *testing.T, mode testMode) {
31563163
t.Errorf("Response line = %q; want a 401", line)
31573164
}
31583165
}
3159-
// Wait for write to finish. This is a broken pipe on both
3160-
// Darwin and Linux, but checking this isn't the point of
3161-
// the test.
3162-
<-writeErr
31633166
return nil
31643167
})
31653168
}

0 commit comments

Comments
 (0)