From 86ae8b3c639bef040625dba03d842298746ca01b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 21 Feb 2013 23:11:40 +0100 Subject: [PATCH] unix: handle EINPROGRESS for unix sockets Before this commit, it was assumed that connect() on UNIX sockets never returns EINPROGRESS. It turned out to be a bad assumption: Dave Pacheco reports sporadic hangups on SmartOS because of that. It's not clear to me _why_ the Illumos kernel returns that error but that's inconsequential: whatever the cause, libuv needs to handle it and now it does. This is a back-port of commit 3348cd7 from the master branch. Fixes joyent/node#4785. Conflicts: src/unix/pipe.c --- src/unix/pipe.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 957e96f8..e0502b03 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -186,16 +186,14 @@ void uv_pipe_connect(uv_connect_t* req, uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path)); saddr.sun_family = AF_UNIX; - /* We don't check for EINPROGRESS. Think about it: the socket - * is either there or not. - */ do { r = connect(handle->fd, (struct sockaddr*)&saddr, sizeof saddr); } while (r == -1 && errno == EINTR); if (r == -1) - goto out; + if (errno != EINPROGRESS) + goto out; if (new_sock) if (uv__stream_open((uv_stream_t*)handle, @@ -216,8 +214,9 @@ out: req->cb = cb; ngx_queue_init(&req->queue); - /* Run callback on next tick. */ - uv__io_feed(handle->loop, &handle->write_watcher, UV__IO_WRITE); + /* Force callback to run on next tick in case of error. */ + if (err != 0) + uv__io_feed(handle->loop, &handle->write_watcher, UV__IO_WRITE); /* Mimic the Windows pipe implementation, always * return 0 and let the callback handle errors.