Skip to content

Commit 9be14c4

Browse files
committed
net: add test that TCP Close unblocks blocked Reads
I guess this was fixed at some point. Remove a skipped test in net/http and add an explicit test in net. Fixes #17695 Change-Id: Idb9f3e236b726bb45098474b830c95c1fce57529 Reviewed-on: https://go-review.googlesource.com/33242 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b687d6a commit 9be14c4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/net/http/serve_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,9 +4907,6 @@ func get(t *testing.T, c *Client, url string) string {
49074907
// Tests that calls to Server.SetKeepAlivesEnabled(false) closes any
49084908
// currently-open connections.
49094909
func TestServerSetKeepAlivesEnabledClosesConns(t *testing.T) {
4910-
if runtime.GOOS == "nacl" {
4911-
t.Skip("skipping on nacl; see golang.org/issue/17695")
4912-
}
49134910
setParallel(t)
49144911
defer afterTest(t)
49154912
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {

src/net/net_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,22 @@ func TestReadTimeoutUnblocksRead(t *testing.T) {
497497
}
498498
withTCPConnPair(t, client, server)
499499
}
500+
501+
// Issue 17695: verify that a blocked Read is woken up by a Close.
502+
func TestCloseUnblocksRead(t *testing.T) {
503+
t.Parallel()
504+
server := func(cs *TCPConn) error {
505+
// Give the client time to get stuck in a Read:
506+
time.Sleep(20 * time.Millisecond)
507+
cs.Close()
508+
return nil
509+
}
510+
client := func(ss *TCPConn) error {
511+
n, err := ss.Read([]byte{0})
512+
if n != 0 || err != io.EOF {
513+
return fmt.Errorf("Read = %v, %v; want 0, EOF", n, err)
514+
}
515+
return nil
516+
}
517+
withTCPConnPair(t, client, server)
518+
}

0 commit comments

Comments
 (0)