1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris
16 // Test that a client can't trigger an endless loop of write system
17 // calls on the server by shutting down the write side on the client.
18 // Possibility raised in the discussion of https://golang.org/cl/71973.
19 func TestEndlessWrite(t
*testing
.T
) {
22 server
:= func(cs
*TCPConn
) error
{
27 client
:= func(ss
*TCPConn
) error
{
28 // Tell the server to return when we return.
31 // Loop writing to the server. The server is not reading
32 // anything, so this will eventually block, and then time out.
33 b
:= bytes
.Repeat([]byte{'a'}, 8192)
36 n
, err
:= ss
.conn
.fd
.pfd
.WriteOnce(b
)
44 // We've written enough data to
45 // start blocking. Set a deadline
46 // so that we will stop.
47 ss
.SetWriteDeadline(time
.Now().Add(5 * time
.Millisecond
))
51 t
.Error("looping on EAGAIN")
54 if err
= ss
.conn
.fd
.pfd
.WaitWrite(); err
!= nil {
55 t
.Logf("client WaitWrite: %v", err
)
59 // We expect to eventually get an error.
60 t
.Logf("client WriteOnce: %v", err
)
65 withTCPConnPair(t
, client
, server
)