On Fri, Sep 17, 2010 at 3:06 PM, Gilad Benjamini <gilad@xxxxxxxxxxxxxxxxx> wrote: >> The first thing to do here is to use event_enable_debug_mode() to have >> libevent track event adds/deletes/etc to make sure that there's >> nothing screwy going on there. (Did this turn anything up? You don't need to build with any special options. There is a build option to *disable* debug mode entirely, but it's available by default.) > Here is the chain of events I was able to identify > - An event for fd 14 is created > - At some later point, my code deletes the event. strace does not show a > call to epoll_ctl to delete fd 14 from the set. > - fd 14 is closed by my code > - Shortly afterwards, there is a call to epoll_ctl to delete fd 14 > - The call fails, of course, and a libevent warning says "DEL was > unnecessary". The comment in that place in the code says "... that's fine > too ... " > - It's not fine. AFAIK, since the file descriptor is closed, epoll did not > actually remove it > - Further down the road, attempts to add fd 14 fail since epoll did not > remove fd 14 in the first place. > > It seems like libevent delays the call to epoll_ctl, and by the time it > actually does that, it's too late. But that's not how epoll behaves, I think. As near as I can tell, closing an fd does indeed remove it from the fds watched by an epoll, and so you can indeed re-add a new file with the same fd. I am basing this on actual testing, with the attached test code. It adds a file to an epoll_fd, then closes the file, then arranges for a new file to get made with the same epoll_fd, then adds the new file. It does not get an EEXIST for me. (I tried this on a 2.6.26 kernel and on a 2.6.34 kernel.) If you can come up with a setup where that sequence of events gives an EEXIST, or if you can tweak the test here until it gives an EEXIST, that would help figuring out how the sequence of events described above could cause an EEXIST. (If you re-enable the #if 0'd code, you'll see that deleting a closed fd from an epoll_fd failes with EBADF.) yrs, -- Nick
Attachment:
epoll_test.c
Description: Binary data