On Wed, Jan 24, 2018 at 8:06 PM, Dave Keck <[email protected]> wrote:
>
> Hey all, this program exits (as expected) when run with macOS 10.12.6 + Go
> 1.8.6, but it deadlocks when run with Go 1.9.3:
>
>     https://play.golang.org/p/Dw_ND9gkgPm
>
> The same behavior is observed when using unix.SetNonblock instead of
> syscall.SetNonblock.
>
> It appears that the SetNonblock() functions don't have an effect in Go
> 1.9.3. Is this a known issue?

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.

Reply via email to