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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/07c52eb0-e075-428d-8d29-9897259eb761n%40googlegroups.com.