Skip to content

Commit

Permalink
darwin: translate EPROTOTYPE to ECONNRESET (#3413)
Browse files Browse the repository at this point in the history
macOS versions 10.10 and 10.15 - and presumbaly 10.11 to 10.14, too -
have a bug where a race condition causes the kernel to return EPROTOTYPE
because the socket isn't fully constructed.

It's probably the result of the peer closing the connection and that is
why libuv translates it to ECONNRESET.

Previously, libuv retried until the EPROTOTYPE error went away but some
VPN software causes the same behavior except the error is permanent, not
transient, turning the retry mechanism into an infinite loop.

Refs: #482
Refs: #3405
  • Loading branch information
bnoordhuis authored Jan 12, 2022
1 parent a3e02e5 commit 3a7b955
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/unix/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,20 @@ static int uv__try_write(uv_stream_t* stream,
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
return UV_EAGAIN;

#ifdef __APPLE__
/* macOS versions 10.10 and 10.15 - and presumbaly 10.11 to 10.14, too -
* have a bug where a race condition causes the kernel to return EPROTOTYPE
* because the socket isn't fully constructed. It's probably the result of
* the peer closing the connection and that is why libuv translates it to
* ECONNRESET. Previously, libuv retried until the EPROTOTYPE error went
* away but some VPN software causes the same behavior except the error is
* permanent, not transient, turning the retry mechanism into an infinite
* loop. See https://github.com/libuv/libuv/pull/482.
*/
if (errno == EPROTOTYPE)
return UV_ECONNRESET;
#endif /* __APPLE__ */

return UV__ERR(errno);
}

Expand Down

0 comments on commit 3a7b955

Please sign in to comment.