go: net: copy from Unix socket to os.Stdout fails with "waiting for unsupported file type"
On HEAD this test function fails:
func TestCopyUnixToStdout(t *testing.T) {
sockPath := filepath.Join(t.TempDir(), "unixsock")
addr, err := net.ResolveUnixAddr("unix", sockPath)
if err != nil {
t.Fatal(err)
}
ln, err := net.ListenUnix("unix", addr)
if err != nil {
t.Fatal(err)
}
defer ln.Close()
go func() {
server, err := ln.Accept()
if err != nil {
t.Error(err)
return
}
defer func() {
if err := server.Close(); err != nil {
t.Error(err)
}
}()
for i := 0; i < 100; i++ {
if _, err := server.Write(bytes.Repeat([]byte{'a'}, 1024)); err != nil {
t.Error(err)
return
}
}
}()
conn, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
t.Fatal(err)
}
if _, err := io.Copy(os.Stdout, conn); err != nil {
t.Fatal(err)
}
}
I see
foo_test.go:50: write /dev/stdout: waiting for unsupported file type
Here line 50 is the t.Fatal called when io.Copy fails.
This test passes with Go 1.20.
This is most likely due to https://go.dev/cl/466015. CC @panjf2000
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (13 by maintainers)
Commits related to this issue
- internal/poll: add SPLICE_F_NONBLOCK flag for splice to avoid inconsistency with O_NONBLOCK For #59041 Details: https://github.com/golang/go/issues/59041#issuecomment-1766610087 Change-Id: Id3fc1df... — committed to golang/go by panjf2000 8 months ago
- internal/poll: add SPLICE_F_NONBLOCK flag for splice to avoid inconsistency with O_NONBLOCK For #59041 Details: https://github.com/golang/go/issues/59041#issuecomment-1766610087 Change-Id: Id3fc1df... — committed to yunginnanet/go by panjf2000 8 months ago
- [release-branch.go1.21] internal/poll: add SPLICE_F_NONBLOCK flag for splice to avoid inconsistency with O_NONBLOCK Fixes #63801 Updates #59041 Updates #63795 Details: https://github.com/golang/go/i... — committed to golang/go by panjf2000 8 months ago
I now think that the stat call was a mistake on my part, and it may not be required at all. Taking it back out. Thanks for raising the issue.