From ff0c603b9be17b74a5a0cda7fd7865cf73887935 Mon Sep 17 00:00:00 2001 From: lzhfromustc <43191155+lzhfromustc@users.noreply.github.com> Date: Wed, 9 Oct 2019 13:12:01 -0400 Subject: [PATCH] proxy_test: Fix a goroutine-leak bug in testHTTPConnect: now use channel done to store err and call t.Fatalf when err not nil (#3080) --- proxy_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proxy_test.go b/proxy_test.go index 42b668bd08c..c9604be6235 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -119,16 +119,16 @@ func testHTTPConnect(t *testing.T, proxyURLModify func(*url.URL) *url.URL, proxy msg := []byte{4, 3, 5, 2} recvBuf := make([]byte, len(msg)) - done := make(chan struct{}) + done := make(chan error) go func() { in, err := blis.Accept() if err != nil { - t.Errorf("failed to accept: %v", err) + done <- err return } defer in.Close() in.Read(recvBuf) - close(done) + done <- nil }() // Overwrite the function in the test and restore them in defer. @@ -154,7 +154,9 @@ func testHTTPConnect(t *testing.T, proxyURLModify func(*url.URL) *url.URL, proxy // Send msg on the connection. c.Write(msg) - <-done + if err := <-done; err != nil { + t.Fatalf("failed to accept: %v", err) + } // Check received msg. if string(recvBuf) != string(msg) {