lab.nexedi.com will be down from Thursday, 20 March 2025, 07:30:00 UTC for a duration of approximately 2 hours

Commit 8b5350b8 authored by Dave Cheney's avatar Dave Cheney

[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
»»»
parent 802ac98f
...@@ -83,9 +83,7 @@ func (c *IPConn) Close() error { ...@@ -83,9 +83,7 @@ func (c *IPConn) Close() error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
err := c.fd.Close() return c.fd.Close()
c.fd = nil
return err
} }
// LocalAddr returns the local network address. // LocalAddr returns the local network address.
......
...@@ -108,9 +108,7 @@ func (c *TCPConn) Close() error { ...@@ -108,9 +108,7 @@ func (c *TCPConn) Close() error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
err := c.fd.Close() return c.fd.Close()
c.fd = nil
return err
} }
// CloseRead shuts down the reading side of the TCP connection. // CloseRead shuts down the reading side of the TCP connection.
......
...@@ -88,9 +88,7 @@ func (c *UDPConn) Close() error { ...@@ -88,9 +88,7 @@ func (c *UDPConn) Close() error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
err := c.fd.Close() return c.fd.Close()
c.fd = nil
return err
} }
// LocalAddr returns the local network address. // LocalAddr returns the local network address.
......
...@@ -141,9 +141,7 @@ func (c *UnixConn) Close() error { ...@@ -141,9 +141,7 @@ func (c *UnixConn) Close() error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
err := c.fd.Close() return c.fd.Close()
c.fd = nil
return err
} }
// LocalAddr returns the local network address, a *UnixAddr. // LocalAddr returns the local network address, a *UnixAddr.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment