• Show log

    Commit

  • Hash : c281aba3
    Author : Nick Mathewson
    Date : 2010-10-24T11:38:29

    Fix a nasty bug related to use of dup() with epoll on Linux
    
    Current versions of the Linux kernel don't seem to remove the struct
    epitem for a given (file,fd) combo when the fd is closed unless the
    file itself is also completely closed.  This means that if you do:
       fd = dup(fd_orig);
       add(fd);
       close(fd);
       dup2(fd_orig, fd);
       add(fd);
    you will get an EEXIST when you should have gotten a success.  This
    could cause warnings and dropped events when using dup and epoll.
    
    The solution is pretty simple: when we get an EEXIST from
    EPOLL_CTL_ADD, we retry with EPOLL_CTL_MOD.
    
    Unit test included to demonstrate the bug.
    
    Found due to the patient efforts of Gilad Benjamini; diagnosed with
    help from Nicholas Marriott.