Skip to content

Commit

Permalink
proxy_test: Fix a goroutine-leak bug in testHTTPConnect: now use chan…
Browse files Browse the repository at this point in the history
…nel done to store err and call t.Fatalf when err not nil (#3080)
  • Loading branch information
lzhfromustc authored and easwars committed Oct 9, 2019
1 parent 2d6a3ed commit ff0c603
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit ff0c603

Please sign in to comment.