kqueue: ignore ENOENT errors when EV_EOF #656

Merged
merged 1 commit into from Dec 18, 2012

Conversation

Projects
None yet
2 participants
Contributor

indutny commented Dec 17, 2012

Some sockets are automatically removed from kqueue upon their
termination, and doing EV_DELETE results in ENOENT. It could be safely
ignored as it isn't a big deal anyway.

This blocks me from using tlsnappy with node 0.9.x, as it abort()s suddenly on a benchmark.

Contributor

indutny commented Dec 17, 2012

@bnoordhuis bnoordhuis and 1 other commented on an outdated diff Dec 17, 2012

src/unix/kqueue.c
@@ -197,7 +197,10 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
/* TODO batch up */
struct kevent events[1];
EV_SET(events + 0, fd, ev->filter, EV_DELETE, 0, 0, 0);
- if (kevent(loop->backend_fd, events, 1, NULL, 0, NULL)) abort();
+ if (kevent(loop->backend_fd, events, 1, NULL, 0, NULL) &&
+ !(ev->flags & EV_EOF)) {
@bnoordhuis

bnoordhuis Dec 17, 2012

Contributor

Shouldn't you check for ENOENT here?

@indutny

indutny Dec 17, 2012

Contributor

Yes, I can do this too...

@indutny

indutny Dec 17, 2012

Contributor

Force pushed.

Contributor

indutny commented Dec 17, 2012

Ok, I nailed it down... Please refer commit message. /cc @bnoordhuis

@bnoordhuis bnoordhuis and 1 other commented on an outdated diff Dec 17, 2012

src/unix/kqueue.c
@@ -167,6 +167,15 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
fd = ev->ident;
w = loop->watchers[fd];
+ /* File descriptor might be closed during callback,
+ * all events that was reported before callback are not valid in such
+ * cases and can be safely ignored
+ */
+ if (w != ev->udata) {
@bnoordhuis

bnoordhuis Dec 17, 2012

Contributor

What happens if the fd is closed, then reopened and added with the same watcher?

Also, this effectively turns the NULL check below into dead code. Probably not what you want.

@indutny

indutny Dec 18, 2012

Contributor

Actually, after sleeping well, I think that ignoring ENOENT is enough.

@indutny indutny kqueue: ignore ENOENT error
File descriptor might be closed during callback, all events that was reported
before the callback are not valid and trying to remove them will result
in ENOENT. This error can be safely ignored.
b86ed94
Contributor

indutny commented Dec 18, 2012

Force pushed. @bnoordhuis

@indutny indutny merged commit b86ed94 into joyent:master Dec 18, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment