Browse Source

go.net/netutil: fix unintentional test deadlock on resource starvation

It's been observed when the node under test has a tiny resource
configutation or package http has changed the behavior of its own
active connection pool.

For example,
http://build.golang.org/log/8912bc0944628cf1b4fe4063a77d36d19f9dd6a3

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/78640043
Mikio Hara 11 years ago
parent
commit
c5088f4913
1 changed files with 3 additions and 2 deletions
  1. 3 2
      netutil/listen_test.go

+ 3 - 2
netutil/listen_test.go

@@ -45,7 +45,8 @@ func TestLimitListener(t *testing.T) {
 		wg.Add(1)
 		go func() {
 			defer wg.Done()
-			r, err := http.Get("http://" + l.Addr().String())
+			c := http.Client{Timeout: 3 * time.Second}
+			r, err := c.Get("http://" + l.Addr().String())
 			if err != nil {
 				t.Logf("Get: %v", err)
 				atomic.AddInt32(&failed, 1)
@@ -60,6 +61,6 @@ func TestLimitListener(t *testing.T) {
 	// We expect some Gets to fail as the kernel's accept queue is filled,
 	// but most should succeed.
 	if failed >= num/2 {
-		t.Errorf("too many Gets failed")
+		t.Errorf("too many Gets failed: %v", failed)
 	}
 }