This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients giampaolo.rodola, gvanrossum, neologix, pitrou, sbt, vstinner
Date 2013-09-14.11:01:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379156518.11.0.97134012587.issue19017@psf.upfronthosting.co.za>
In-reply-to
Content
Currently, in case of invalid file descriptor (which can happen easily e.g. if the user closes the FD before unregistering it), selector.select() will react differently depending on the backend:

SelectSelector fails with EBADF
PollSelector returns EVENT_READ/EVENT_WRITE for the FD (translated from poll()'s POLLNVAL)
EpollSelector returns nothing (epoll silently removes the FD from the set of monitored FD, there's no EPOLLNVAL)
KqueueSelector behaves like EpollSelector

One possibility would be for PollSelector.select() to raise EBADF in case of POLLNVAL. That would be consistent with select, but not with epoll and kqueue.

Another possibility would be to silently fix those, i.e. in case of EBADF/POLLNVAL in select/poll, remove the offending FD from the list of monitored FDs. That's what libev does (see e.g. http://cvs.schmorp.de/libev/ev_poll.c?revision=1.39&view=markup and http://cvs.schmorp.de/libev/ev.c?revision=1.457&view=markup), and that's also what twisted does, at least for select (see http://twistedmatrix.com/trac/browser/trunk/twisted/internet/selectreactor.py#L77).

One advantage is that once we've detected a bad FD, we remove it so we're sure we won't loop endlessly: e.g. for poll, if the user doesn't try to use the FD no exception will be raised and selector.select() keep reporting the FD ready.

(Note that performing this cleanup is easy for poll since it's flagged with POLLNVAL, but for select this requires looping over the registered FDs, but since that's only called in case of error, it's not performance critical, see Twisted's code)

I personally favor the later solution.

Second point: if we opt for the later solution, we should probably update {EpollSelector,KqueueSelector}.unregister() to silently catch an error if the FD wasn't registered in the underlying epoll/kqueue.
That's what libev does, and amusingly that's what the select module already does:
http://hg.python.org/cpython/file/c9644c1f9c94/Modules/selectmodule.c#l1329

Third point: should the current select behavior (ignoring epoll.unregister() error) be kept?

Thoughts?
History
Date User Action Args
2013-09-14 11:01:58neologixsetrecipients: + neologix, gvanrossum, pitrou, vstinner, giampaolo.rodola, sbt
2013-09-14 11:01:58neologixsetmessageid: <1379156518.11.0.97134012587.issue19017@psf.upfronthosting.co.za>
2013-09-14 11:01:57neologixlinkissue19017 messages
2013-09-14 11:01:56neologixcreate