net: avoid wrapping io.EOF in UnixConn read methods
The io.Reader contract requires that Read methods return io.EOF
directly instead of wrapping it in another error.
Currently UnixConn.ReadFromUnix, ReadFrom, and ReadMsgUnix wrap
io.EOF inside net.OpError, causing callers checking for io.EOF
to fail.
Fix by avoiding wrapping when err == io.EOF.
Fixes #78137
diff --git a/src/net/unixsock.go b/src/net/unixsock.go
index 0ee79f3..d1bf1d3 100644
--- a/src/net/unixsock.go
+++ b/src/net/unixsock.go
@@ -108,7 +108,7 @@
return 0, nil, syscall.EINVAL
}
n, addr, err := c.readFrom(b)
- if err != nil {
+ if err != nil && err != io.EOF {
err = &OpError{Op: "read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
}
return n, addr, err
@@ -120,7 +120,7 @@
return 0, nil, syscall.EINVAL
}
n, addr, err := c.readFrom(b)
- if err != nil {
+ if err != nil && err != io.EOF {
err = &OpError{Op: "read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
}
if addr == nil {
@@ -141,7 +141,7 @@
return 0, 0, 0, nil, syscall.EINVAL
}
n, oobn, flags, addr, err = c.readMsg(b, oob)
- if err != nil {
+ if err != nil && err != io.EOF {
err = &OpError{Op: "read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
}
return
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
A change like this should have a test case. It also needs a release note. Thanks.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
func TestUnixConnReadMsgUnixEOF(t *testing.T) {
Thanks for the CL!
I don't think we need a new dedicated test file here. Let's just put this in `net/unixsock_test.go`.
Also, let's exercise all the `Read` methods in the test rather than just `ReadMsgUnix`.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks for the CL!
I don't think we need a new dedicated test file here. Let's just put this in `net/unixsock_test.go`.
Also, let's exercise all the `Read` methods in the test rather than just `ReadMsgUnix`.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
src/go.mod and src/make.bash were accidentally deleted in the patchset 3.
Restored them in this patchset.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
net: UnixConn read methods now return io.EOF directly instead of wrapping it in net.OpError when the underlying read reaches EOF.Add a line break.
s/reaches EOF/returns EOF/
switch runtime.GOOS {It's not necessarily a problem for this CL but it's kind of weird that this switch is not handled by testableNetwork. Or, more specifically, supportsUnixSocket.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
net: UnixConn read methods now return io.EOF directly instead of wrapping it in net.OpError when the underlying read reaches EOF.Add a line break.
s/reaches EOF/returns EOF/
Done
It's not necessarily a problem for this CL but it's kind of weird that this switch is not handled by testableNetwork. Or, more specifically, supportsUnixSocket.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
Skip test on Windows to avoid unix socket incompatibility. Also removed the redundant GOOS switch as suggested.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |