--- libev/ev_epoll.c 2007/11/04 22:03:17 1.18 +++ libev/ev_epoll.c 2007/11/04 23:14:11 1.19 @@ -43,7 +43,9 @@ | (nev & EV_WRITE ? EPOLLOUT : 0); if (epoll_ctl (epoll_fd, mode, fd, &ev)) - fd_kill (EV_A_ fd); + if (errno != ENOENT /* on ENOENT the fd went away, so try to do the right thing */ + || (nev && epoll_ctl (epoll_fd, EPOLL_CTL_ADD, fd, &ev))) + fd_kill (EV_A_ fd); } static void