diff options
author | Dave Cheney <dave@cheney.net> | 2012-04-21 10:01:32 +1000 |
---|---|---|
committer | Dave Cheney <dave@cheney.net> | 2012-04-21 10:01:32 +1000 |
commit | 8b5350b8e4b8b23c49f8e8386d4a57848738a867 (patch) | |
tree | f66351a7efecd9da5cc87b76d623de0a74750ba8 | |
parent | 802ac98ffc5415c693a392bb1c2b3a693765bdd2 (diff) | |
download | go-8b5350b8e4b8b23c49f8e8386d4a57848738a867.tar.gz go-8b5350b8e4b8b23c49f8e8386d4a57848738a867.zip |
[release-branch.go1] net: fix race between Close and Read
««« backport 5f24ff99b5f1
net: fix race between Close and Read
Fixes #3507.
Applied the suggested fix from rsc. If the connection
is in closing state then errClosing will bubble up to
the caller.
The fix has been applied to udp, ip and unix as well as
their code path include nil'ing c.fd on close. Func
tests are available in the linked issue that verified
the bug existed there as well.
R=rsc, fullung, alex.brainman, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/6002053
»»»
-rw-r--r-- | src/pkg/net/iprawsock_posix.go | 4 | ||||
-rw-r--r-- | src/pkg/net/tcpsock_posix.go | 4 | ||||
-rw-r--r-- | src/pkg/net/udpsock_posix.go | 4 | ||||
-rw-r--r-- | src/pkg/net/unixsock_posix.go | 4 |
4 files changed, 4 insertions, 12 deletions
diff --git a/src/pkg/net/iprawsock_posix.go b/src/pkg/net/iprawsock_posix.go index 6bbe67c3d9..9fc7ecdb94 100644 --- a/src/pkg/net/iprawsock_posix.go +++ b/src/pkg/net/iprawsock_posix.go @@ -83,9 +83,7 @@ func (c *IPConn) Close() error { if !c.ok() { return syscall.EINVAL } - err := c.fd.Close() - c.fd = nil - return err + return c.fd.Close() } // LocalAddr returns the local network address. diff --git a/src/pkg/net/tcpsock_posix.go b/src/pkg/net/tcpsock_posix.go index 15f8efdd70..f886a6b5c5 100644 --- a/src/pkg/net/tcpsock_posix.go +++ b/src/pkg/net/tcpsock_posix.go @@ -108,9 +108,7 @@ func (c *TCPConn) Close() error { if !c.ok() { return syscall.EINVAL } - err := c.fd.Close() - c.fd = nil - return err + return c.fd.Close() } // CloseRead shuts down the reading side of the TCP connection. diff --git a/src/pkg/net/udpsock_posix.go b/src/pkg/net/udpsock_posix.go index 9e820e1c57..9c6b6d3933 100644 --- a/src/pkg/net/udpsock_posix.go +++ b/src/pkg/net/udpsock_posix.go @@ -88,9 +88,7 @@ func (c *UDPConn) Close() error { if !c.ok() { return syscall.EINVAL } - err := c.fd.Close() - c.fd = nil - return err + return c.fd.Close() } // LocalAddr returns the local network address. diff --git a/src/pkg/net/unixsock_posix.go b/src/pkg/net/unixsock_posix.go index 37a2b1e09e..ea411a65f0 100644 --- a/src/pkg/net/unixsock_posix.go +++ b/src/pkg/net/unixsock_posix.go @@ -141,9 +141,7 @@ func (c *UnixConn) Close() error { if !c.ok() { return syscall.EINVAL } - err := c.fd.Close() - c.fd = nil - return err + return c.fd.Close() } // LocalAddr returns the local network address, a *UnixAddr. |