I think you put this issue on the Go issue board? https://github.com/golang/go/issues/66239 Seems like the bug has been confirmed or at least it's being looked at
On Monday, March 11, 2024 at 2:04:19 PM UTC Jay Goel wrote: > Hello, > > I believe there is a bug where, on Mac, reading a named pipe with > O_NONBLOCK is blocking on Read(). I am not able to reproduce this on Linux. > > This example is on go version go1.22.1 darwin/arm64, and I am running an > M1 2020 macbook with OS version 12.5 (21G72). > > I believe there is some race condition involved, as I'm only able to > reproduce this when invoking time.Sleep() between writes. Here is my writer: > > go func() { > pipe, _ := os.OpenFile("p.pipe", os.O_WRONLY|os.O_APPEND, os.ModeNamedPipe) > for range 5 { > pipe.WriteString("Hello\n") > time.Sleep(1000 * time.Millisecond) > } > err := pipe.Close() > }() > > And here is my reader: > > pipe, _ := os.OpenFile("p.pipe", os.O_RDONLY|syscall.O_NONBLOCK, > os.ModeNamedPipe) > buf := make([]byte, 1) > for { > n, err := pipe.Read(buf) > fmt.Println(n, err) > } > > After pipe.Close() finishes, then pipe.Read() blocks indefinitely. I would > expect the for loop to run infinitely with an EOF error. > > Curiously, when I remove the time.Sleep(), then the code behaves as > expected. > > The actual problem I'm solving is to pipe the output of one process, which > writes to a named pipe, to an HTTP writer. But this is the simplest > example I can find to reproduce the issue. > > The full program listing is here: > https://gist.github.com/poundifdef/76377b75b15826baccab83cd501d0c85 > > Thank you, > Jay Goel > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/186aa5b6-f2ba-43e4-b831-93bbce3cab3cn%40googlegroups.com.