From e6168df52077e40d600807dc0096c1ed4fd99a13 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 13 Feb 2018 16:01:43 +0100 Subject: [PATCH] osx,stream: retry sending handle on EMSGSIZE error On OSX when sending handles via `sendmsg()` it can return `EMSGSIZE` if there isn't room in the socket output buffer to store the whole message. If that's the case, return control to the loop and try again in the next iteration. Fixes: https://github.com/nodejs/node/issues/14828 PR-URL: https://github.com/libuv/libuv/pull/1739 Reviewed-By: Colin Ihrig --- src/unix/stream.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/unix/stream.c b/src/unix/stream.c index 5aa60431..3e786abe 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -58,6 +58,12 @@ struct uv__stream_select_s { fd_set* swrite; size_t swrite_sz; }; +# define WRITE_RETRY_ON_ERROR(send_handle) \ + (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || \ + (errno == EMSGSIZE && send_handle)) +#else +# define WRITE_RETRY_ON_ERROR(send_handle) \ + (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS) #endif /* defined(__APPLE__) */ static void uv__stream_connect(uv_stream_t*); @@ -859,7 +865,7 @@ start: } if (n < 0) { - if (errno != EAGAIN && errno != EWOULDBLOCK && errno != ENOBUFS) { + if (!WRITE_RETRY_ON_ERROR(req->send_handle)) { err = UV__ERR(errno); goto error; } else if (stream->flags & UV_STREAM_BLOCKING) {