Author njs
Recipients njs, vstinner
Date 2017-04-11.10:35:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491906934.77.0.432375988854.issue30038@psf.upfronthosting.co.za>
In-reply-to
Content
Right. My claim would be that the PR I just submitted is the correct fix for bpo-21645 as well.

The approach asyncio uses is very elegant, but unfortunately it assumes that the wakeup fd has infinite buffer, which isn't true. If enough signals or other callbacks are scheduled to the event loop quickly enough, then the buffer can overflow and signals can get lost. This is a very classic issue and source of confusion for everyone learning Unix – the reason that there are traditionally 32 unix signals, and that signals can be coalesced and SIGCHLD is so annoying, is that the kernel treats pending signals as flags, not a queue; this means that in the worst case it only takes 32 bits to store all pending signals. (Even the posix committee screwed this up when designing the real-time signals system, which is almost unusable as a result.) On Unix, if you send a process 10 SIGHUP and 1 SIGCHLD, then it might get only 1 SIGHUP and 1 SIGCHLD, but it's guaranteed to get that. With asyncio's model, it might get 10 SIGHUP and 0 SIGCHLD, or even 0 SIGHUP and 0 SIGCHLD (since other methods like call_soon_threadsafe also write to the wakeup fd).

In any case, this is why other async libraries (at least twisted, libuv, tornado, trio) treat the wakeup fd as a boolean empty-or-not, and pass the actual information via some other out-of-band mechanism that involves a Python-level signal handler. So the patch here is necessary for everyone else to safely use set_wakeup_fd.
History
Date User Action Args
2017-04-11 10:35:34njssetrecipients: + njs, vstinner
2017-04-11 10:35:34njssetmessageid: <1491906934.77.0.432375988854.issue30038@psf.upfronthosting.co.za>
2017-04-11 10:35:34njslinkissue30038 messages
2017-04-11 10:35:34njscreate