mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
7ce361737f
commit
5cec8b85e5
1 changed files with 7 additions and 0 deletions
|
|
@ -316,6 +316,13 @@ func (s *Server) wrap() {
|
||||||
s.Config.ConnState = func(c net.Conn, cs http.ConnState) {
|
s.Config.ConnState = func(c net.Conn, cs http.ConnState) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
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 {
|
switch cs {
|
||||||
case http.StateNew:
|
case http.StateNew:
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue