diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-09-12 07:09:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-12 07:09:54 (GMT) |
commit | 530d1105ed7b0aa5ef76e3116918fe39bc6a4823 (patch) | |
tree | f9c29b8380126b4eb772d6615b39fd05e9132267 /Lib/asyncio/proactor_events.py | |
parent | 77901dc6c3d06dd31f6c84b2d3cb21dc26b1e351 (diff) | |
download | cpython-530d1105ed7b0aa5ef76e3116918fe39bc6a4823.zip cpython-530d1105ed7b0aa5ef76e3116918fe39bc6a4823.tar.gz cpython-530d1105ed7b0aa5ef76e3116918fe39bc6a4823.tar.bz2 |
bpo-39651: Fix asyncio proactor _write_to_self() (GH-22197)
Fix a race condition in the call_soon_threadsafe() method of
asyncio.ProactorEventLoop: do nothing if the self-pipe socket has
been closed.
(cherry picked from commit 1b0f0e3d7d03155da1cf9769a847874d559e57e3)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib/asyncio/proactor_events.py')
-rw-r--r-- | Lib/asyncio/proactor_events.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index 54e4deb..3e0a14f 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -791,8 +791,17 @@ class BaseProactorEventLoop(base_events.BaseEventLoop): f.add_done_callback(self._loop_self_reading) def _write_to_self(self): + # This may be called from a different thread, possibly after + # _close_self_pipe() has been called or even while it is + # running. Guard for self._csock being None or closed. When + # a socket is closed, send() raises OSError (with errno set to + # EBADF, but let's not rely on the exact error code). + csock = self._csock + if csock is None: + return + try: - self._csock.send(b'\0') + csock.send(b'\0') except OSError: if self._debug: logger.debug("Fail to write a null byte into the " |