[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Forked processes and signals

On Sun, Mar 6, 2011 at 2:43 PM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
> On Sat, Mar 5, 2011 at 4:59 AM, Christophe Fillot <cf@xxxxxx> wrote:
> [...]
>> I guess this behavior is related to the epoll mechanism.
> Hi, Christophe!  I just tried your code and found out that the bug
> does not appear on OSX 10.5 at all, but does appear on Linux whether
> it's using the epoll mechanism or not (whien I set the EVENT_NOEPOLL
> environment variable, it will still send signals to the subprocesses,
> unless the evsig_)
> So it's probably not epoll.  I thought it might be eventfd, since
> that's also Linux-specific, but when I tried rebuilding the code
> without eventfd enabled, it still didn't work. (Assmuming I did it
> right.)  Both platforms also have signal and sigaction, so it doesn't
> seem likely to be a signal/sigaction difference.  My inlaws are in
> town, so I shouldn't glue myself to the computer much longer today,
> but I'll try to investigate more soon.

Aha.  My testing was off, this makes more sense now.

The problem is indeed epoll-backend related.  The problem is that
after the fork, the subprocess shares the epoll fd with the parent
process, and these both refer to the same kernel epoll structure.
Ordinarily, you would call event_reinit() before using it, so that the
subprocess would now have its own separate structure.  But if you
instead call event_base_free() immediately, the subprocess calls
evsig_dealloc(), which calls event_del() on the ev_signal event, which
unregisters it from the shared epoll structure, so the master process
doesn't get signal events any more.

The workaround for now is to do event_reinit() *then*
event_base_free() in the subprocess.  I've tested it, and it seems to
work on Linux for me.

The real fix is to make event_base_free() a bit smarter about the
epoll case.  This seems tricky; it probably wants to be a 2.1 fix,
since there is a workaround for 2.0.  I've opened a bug ticked so this
doesn't get forgotten: fixes are welcome!  (The ticket is at

To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.