[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] [nicholas.marriott@xxxxxxxxx: libevent and invalid fds]
On Wed, Feb 08, 2012 at 11:37:45AM -0500, Nick Mathewson wrote:
> On Tue, Feb 7, 2012 at 1:47 PM, Nicholas Marriott
> <nicholas.marriott@xxxxxxxxx> wrote:
> > Forwarding this message to ML at Nick's request...
> >
> > Hi
> >
> > You may remember a few months ago you fixed a problem with kqueue and
> > EPIPE on pipes - I backported this fix to 1.4 and recently applied it to
> > OpenBSD.
> >
> > However, this is causing problems with Google Chrome. From what we can
> > gather it appears the problem is with EBADF - when kqueue returns EBADF
> > for an fd, libevent fires the read callback, same as for EPIPE. This
> > makes Chrome segfault somewhere in a huge mess of C++ that I can't
> > figure my way through.
>
> Hm. So IIRC, we first added that EBADF in, it was (supposedly)
> because some kqueue implementations produced EBADF in response to one
> side of a pipe being closed while we were watching the other with
> kqueue.
>
> Do we know what platform or platforms this might have been? I'm not
> convinced atm that it's a real thing. I've attached a small test
> program that tries closing the read and the write side of a pipe, both
> before and after the point where it is added to the kqueue. Can we
> find any platform where it says "bad file descriptor"? If not, your
> fix would indeed seem to be the easy way around the present issue.
Well, I guess for a full fix things should perhaps be made
consistent. Every backend seems to behave differently when adding a
closed file descriptor.
This is on Linux:
$ ./evtestx
[warn] Epoll ADD(5) on fd 3 failed. Old events were 0; read change was 1 (add); write change was 1 (add): Bad file descriptor
evtestx: event_add: Bad file descriptor
$ EVENT_NOEPOLL=1 ./evtestx
^C
$ EVENT_NOEPOLL=1 EVENT_NOPOLL=1 ./evtestx
[warn] select: Bad file descriptor
evtestx: event_dispatch: Bad file descriptor
So currently: kqueue fires an event, select exits the event loop, poll
does nothing, epoll causes event_add to fail.
My change will make kqueue behave like it did before and do nothing -
the same as poll. Whether epoll and select also need to be fixed I'm not
sure.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.