Thanks for the explanation and the solution :) Where is this behaviour documented?
The current documentation https://golang.org/pkg/os does not indicate blocking vs non blocking behaviour of *os.File and of functions that return *os.File, as for example os.Pipe() Also, os.File.Fd() having side effects seems very unexpected and surprising at least to me. Best regards, Max As of 1.9 os.Pipe returns non-blocking descriptors by default. In > order to be consistent with past releases, when you call the Fd > method, the descriptor is explicitly set back into blocking mode, > since that is how Fd behaved in the past. In your code you are > calling > syscall.Read(int(pr.Fd()), make([]byte, 1, 1)) > so the effect of calling pr.Fd() is to undo the earlier call to > syscall.SetNonblock. > > This is an unfortunate consequence of reasonable decisions. > Fortunately the fix for your code is simple: write `fd := pr.Fd()` and > then use that, rather than calling the Fd method several times. Or, > perhaps, just trust that pipe's won't be in blocking mode and let the > Go runtime handle them efficiently, rather than trying to do your own > nonblocking I/O. > > Ian > -- 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]. For more options, visit https://groups.google.com/d/optout.
