diff options
author | Damien Neil <dneil@google.com> | 2021-03-25 11:11:03 -0700 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2021-12-01 22:15:01 +0000 |
commit | 0f9838eeb119ef9c49e70a8388c25f02567a5a14 (patch) | |
tree | 00e7099822934f7d68f3549f913318ec9bffa48b | |
parent | 266ee22f9c35774caa118225e52e97c4eb06f961 (diff) | |
download | go-0f9838eeb119ef9c49e70a8388c25f02567a5a14.tar.gz go-0f9838eeb119ef9c49e70a8388c25f02567a5a14.zip |
[release-branch.go1.16] net/http/httptest: wait for user ConnState hooks
Ensure that user ConnState callbacks have completed before returning
from (*httptest.Server).Close.
Fixes: #49851
Updates: #37510
Updates: #37505
Updates: #45237
Change-Id: I8fe7baa089fbe4f3836bf6ae9767c7b1270d1331
Reviewed-on: https://go-review.googlesource.com/c/go/+/304829
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
(cherry picked from commit 5cec8b85e5dc75ef21b62efb6bd93f9007385e34)
Reviewed-on: https://go-review.googlesource.com/c/go/+/367516
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
-rw-r--r-- | src/net/http/httptest/server.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/net/http/httptest/server.go b/src/net/http/httptest/server.go index 65165d9eb3..a02a6d64c3 100644 --- a/src/net/http/httptest/server.go +++ b/src/net/http/httptest/server.go @@ -316,6 +316,13 @@ func (s *Server) wrap() { s.Config.ConnState = func(c net.Conn, cs http.ConnState) { s.mu.Lock() defer s.mu.Unlock() + + // Keep Close from returning until the user's ConnState hook + // (if any) finishes. Without this, the call to forgetConn + // below might send the count to 0 before we run the hook. + s.wg.Add(1) + defer s.wg.Done() + switch cs { case http.StateNew: s.wg.Add(1) |