]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: avoid leaking the writing goroutine
authorMichael Fraenkel <michael.fraenkel@gmail.com>
Fri, 28 Apr 2023 13:14:08 +0000 (07:14 -0600)
committerGopher Robot <gobot@golang.org>
Tue, 2 May 2023 12:56:19 +0000 (12:56 +0000)
The test will wait for all goroutines.
A race can occur if the writing goroutine uses the Log after the test exits.

For #58264
For #59883
For #59884

Change-Id: I9b8ec7c9d024ff74b922b69efa438be5a4fa3483
Reviewed-on: https://go-review.googlesource.com/c/go/+/490255
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>

src/net/http/serve_test.go

index 9b8496e7ad091de58f354358e06d9ceb0abee9ed..819152658bffb89e1207da0c5430570eff30bedd 100644 (file)
@@ -1744,7 +1744,13 @@ func testServerExpect(t *testing.T, mode testMode) {
                // that doesn't send 100-continue expectations.
                writeBody := test.contentLength != 0 && strings.ToLower(test.expectation) != "100-continue"
 
+               wg := sync.WaitGroup{}
+               wg.Add(1)
+               defer wg.Wait()
+
                go func() {
+                       defer wg.Done()
+
                        contentLen := fmt.Sprintf("Content-Length: %d", test.contentLength)
                        if test.chunked {
                                contentLen = "Transfer-Encoding: chunked"