Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created March 20, 2012 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/2140458 to your computer and use it in GitHub Desktop.
Save isaacs/2140458 to your computer and use it in GitHub Desktop.
From e0aeb95dbf91c6dff27f88ac22910d2c0278a255 Mon Sep 17 00:00:00 2001
From: Robert Mustacchi <rm@joyent.com>
Date: Tue, 20 Mar 2012 12:40:48 -0700
Subject: [PATCH] Need to handle ECONNABORTED.
---
src/unix/stream.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/unix/stream.c b/src/unix/stream.c
index 111bbc2..08d1971 100644
--- a/src/unix/stream.c
+++ b/src/unix/stream.c
@@ -176,7 +176,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) {
fd = uv__accept(stream->fd, (struct sockaddr*)&addr, sizeof addr);
if (fd < 0) {
- if (errno == EAGAIN) {
+ if (errno == EAGAIN || errno == ECONNABORTED) {
/* No problem. */
return;
} else if (errno == EMFILE) {
--
1.7.3.3
@bnoordhuis
Copy link

That patch doesn't look right. If there are 2 pending connections and the first one fails with ECONNABORTED, then a) the second one won't get accepted and b) the event loop will probably stall if it's edge-triggered. I suggest this instead:

diff --git a/src/unix/stream.c b/src/unix/stream.c
index b5ade16..976f73d 100644
--- a/src/unix/stream.c
+++ b/src/unix/stream.c
@@ -185,6 +185,8 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) {
       } else if (errno == EMFILE) {
         /* TODO special trick. unlock reserved socket, accept, close. */
         return;
+      } else if (errno == ECONNABORTED) {
+        /* ignore */
+        continue;
       } else {
         uv__set_sys_error(stream->loop, errno);
         stream->connection_cb((uv_stream_t*)stream, -1);

cc @rmustacc

@isaacs
Copy link
Author

isaacs commented Mar 21, 2012

@bnoordhuis That lgtm. AFAICT, should ignore the econnaborted just as surely, but without missing any other connections.

@piscisaureus
Copy link

@bnoordhuis: On Windows read() reports ECONNABORTED sometimes. We turn this into ECONNRESET to be consistent with linux. Does uv-unix need something similar for BSDs?

@bnoordhuis
Copy link

On Windows read() reports ECONNABORTED sometimes. We turn this into ECONNRESET to be consistent with linux. Does uv-unix need something similar for BSDs?

Well, maybe. Simply ignoring ECONNABORTED seems easier though, both for us and libuv users.

@piscisaureus
Copy link

Well, I'm talking about read returning ECONNABORTED. We have to make the callback, because otherwise the user would leak uv_buf_ts.

@bnoordhuis
Copy link

Oh, hah - yeah, I was still talking about accept().

@piscisaureus
Copy link

Ok so let me repeat the question. On Windows read() reports ECONNABORTED sometimes. We turn this into ECONNRESET to be consistent with linux. Does uv-unix need something similar for BSDs?

@isaacs
Copy link
Author

isaacs commented Mar 21, 2012

I don't think we need to do anything with read(). The important thing is that we get this accept() bug fixed. It's causing injuries currently.

@isaacs
Copy link
Author

isaacs commented Mar 21, 2012

According to @rmustacc, it's not possible for read(2) to return that on sunos. I don't see any mention of it in the BSD man pages, either. Let's just make the change for accept only.

@bnoordhuis
Copy link

it's not possible for read(2) to return that on sunos

Same on Linux. It makes sense when you think about it. I landed a patch in joyent/libuv@c9c9d80.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment