From: Michael Fraenkel Date: Fri, 28 Apr 2023 13:14:08 +0000 (-0600) Subject: net/http: avoid leaking the writing goroutine X-Git-Tag: go1.21rc1~722 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c63066123bb5c2ef7a6d26d1a6e3e5f1012a1e23;p=gostls13.git net/http: avoid leaking the writing goroutine 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 Reviewed-by: Bryan Mills Run-TryBot: Damien Neil TryBot-Result: Gopher Robot Auto-Submit: Bryan Mills --- diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index 9b8496e7ad..819152658b 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -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"