Skip to content

Commit

Permalink
stream: retry write on EPROTOTYPE on OS X
Browse files Browse the repository at this point in the history
At least on OS X 10.10 "Yosemite", an EPROTOTYPE can occur
when trying to write to a socket that is shutting down.
By retrying the write after EPROTOTYPE, we correctly get EPIPE.
  • Loading branch information
mscdex committed Aug 17, 2015
1 parent 939ea06 commit 94067e4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/unix/stream.c
Expand Up @@ -809,7 +809,17 @@ static void uv__write(uv_stream_t* stream) {
do {
n = sendmsg(uv__stream_fd(stream), &msg, 0);
}
#if defined(__APPLE__)
/*
* Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
* EPROTOTYPE can be returned while trying to write to a socket that is
* shutting down. If we retry the write, we should get the expected EPIPE
* instead.
*/
while (n == -1 && (errno == EINTR || errno == EPROTOTYPE));
#else
while (n == -1 && errno == EINTR);
#endif
} else {
do {
if (iovcnt == 1) {
Expand All @@ -818,7 +828,17 @@ static void uv__write(uv_stream_t* stream) {
n = writev(uv__stream_fd(stream), iov, iovcnt);
}
}
#if defined(__APPLE__)
/*
* Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
* EPROTOTYPE can be returned while trying to write to a socket that is
* shutting down. If we retry the write, we should get the expected EPIPE
* instead.
*/
while (n == -1 && (errno == EINTR || errno == EPROTOTYPE));
#else
while (n == -1 && errno == EINTR);
#endif
}

if (n < 0) {
Expand Down

0 comments on commit 94067e4

Please sign in to comment.