Hello! I think I’ve found a bug with go 1.22.1 on an M1 mac and I’d love to know if anyone knows what is going on. When I try to read from a named pipe with O_NONBLOCK
, then calls to Read()
still block after the pipe is closed.
This only happens when I write to the pipe slowly, using time.Sleep()
. This 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")
// Removing this Sleep() does not cause this bug
time.Sleep(1000 * time.Millisecond)
}
err := pipe.Close()
fmt.Println("Writer closed pipe", err)
}()
And my reader:
pipe, _ := os.OpenFile("p.pipe", os.O_RDONLY|syscall.O_NONBLOCK, os.ModeNamedPipe)
buf := make([]byte, 1)
for {
// This should loop infinitely, even after the writer closes the pipe
// However, after the pipe is closed, Read() blocks
n, err := pipe.Read(buf)
fmt.Println("Read from pipe", n, err)
}
The full program is here: Named pipes with O_NONBLOCK still block · GitHub
I’m running go version go1.22.1 darwin/arm64; M1 2020 macbook with OS version 12.5 (21G72)