mirror of
https://github.com/golang/go
synced 2024-11-19 20:54:39 -07:00
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
This commit is contained in:
parent
904c7c8e99
commit
1f14d45e7d
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user