]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] net: fix race between Close and Read
authorDave Cheney <dave@cheney.net>
Sat, 21 Apr 2012 00:01:32 +0000 (10:01 +1000)
committerDave Cheney <dave@cheney.net>
Sat, 21 Apr 2012 00:01:32 +0000 (10:01 +1000)
««« 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
»»»

src/pkg/net/iprawsock_posix.go
src/pkg/net/tcpsock_posix.go
src/pkg/net/udpsock_posix.go
src/pkg/net/unixsock_posix.go

index 6bbe67c3d9a65216a5e637422cc7d06b8f40b910..9fc7ecdb942a34f6cc05f318fe3cf3312fd45154 100644 (file)
@@ -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.
index 15f8efdd7013fabbf83aebb66ac8791adafbab31..f886a6b5c5b1f473b68c9dc92d62fb01861cc7dc 100644 (file)
@@ -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.
index 9e820e1c57acd716c7f016983f6c72e8d6334b6d..9c6b6d39336a39e37c3cd0dca22fc5622c98a28d 100644 (file)
@@ -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.
index 37a2b1e09ece3e29ade1b2b73ef8e55afd82f938..ea411a65f0aa8d7e6f62529a92705642a1994307 100644 (file)
@@ -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.