Skip to content

Commit 5cec8b8

Browse files
committed
net/http/httptest: wait for user ConnState hooks
Ensure that user ConnState callbacks have completed before returning from (*httptest.Server).Close. Fixes: #37510 Fixes: #37505 Fixes: #45237 Change-Id: I8fe7baa089fbe4f3836bf6ae9767c7b1270d1331 Reviewed-on: https://go-review.googlesource.com/c/go/+/304829 Trust: Damien Neil <[email protected]> Run-TryBot: Damien Neil <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 7ce3617 commit 5cec8b8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/net/http/httptest/server.go

+7
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ func (s *Server) wrap() {
316316
s.Config.ConnState = func(c net.Conn, cs http.ConnState) {
317317
s.mu.Lock()
318318
defer s.mu.Unlock()
319+
320+
// Keep Close from returning until the user's ConnState hook
321+
// (if any) finishes. Without this, the call to forgetConn
322+
// below might send the count to 0 before we run the hook.
323+
s.wg.Add(1)
324+
defer s.wg.Done()
325+
319326
switch cs {
320327
case http.StateNew:
321328
s.wg.Add(1)

0 commit comments

Comments
 (0)