From 8fe4ca686bcb069f670b0381e89c008ca814f8ba Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 28 Sep 2013 10:29:53 +0200 Subject: [PATCH] unix: set O_NONBLOCK in uv_pipe_open() Don't rely on the caller to set the O_NONBLOCK flag on the file descriptor. Prevents sporadic stalls when the file descriptor is in blocking mode and exactly as many bytes are read as there are available; in that case, libuv will try to read again and block. Node.js was guilty of this. Fixes #941. --- src/unix/pipe.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 4b7f966b..6db16812 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -160,6 +160,9 @@ int uv_pipe_open(uv_pipe_t* handle, uv_file fd) { return -1; #endif /* defined(__APPLE__) */ + if (uv__nonblock(fd, 1)) + return uv__set_sys_error(handle->loop, errno); + return uv__stream_open((uv_stream_t*)handle, fd, UV_STREAM_READABLE | UV_STREAM_WRITABLE);