eventlet/eventlet — pull request #68 by neilrahilly (2013-12-13 01:45:38+00:00)
Title: Atfork

This fixes #80. The issue is that a parent and child process can end up sharing an instance of epoll after a fork. Since file descriptors are unique only within a process, the two processes can end up with the same file descriptor pointing to two completely different resources. So the child registers socket A with FD 3 and the parent registers socket B with FD 3, and epoll gets messed up. These conflicts are likely because Linux will use the lowest free number for creating a new file descriptors.

We found this happening at Mixpanel in one of our services that's deployed using a prefork server. If some code causes the server process to create an eventlet hub prior to the fork, the master and workers all share the same epoll instance, and strange behavior ensues.

More generally, like threads, it doesn't make much sense to have child process inherit its parents state. Therefore, we decided to clean the parent's hub out of the child after fork. Any subsequent use of eventlet in the child will generate a new hub.