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

Most upvoted comments

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.