summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-09-03 19:38:34 (GMT)
committerGitHub <noreply@github.com>2020-09-03 19:38:34 (GMT)
commita986b061a3cd4661eb9f857e2936291f1847bd15 (patch)
tree140f444860fd00133352196aca55a6a3c1fa0c9a /Lib/asyncio
parent9fef7c54a0adfade5ec94259d97f22e05fe9e3e3 (diff)
downloadcpython-a986b061a3cd4661eb9f857e2936291f1847bd15.zip
cpython-a986b061a3cd4661eb9f857e2936291f1847bd15.tar.gz
cpython-a986b061a3cd4661eb9f857e2936291f1847bd15.tar.bz2
bpo-39010: Fix errors logged on proactor loop restart (GH-22017) (#22035)
Stopping and restarting a proactor event loop on windows can lead to spurious errors logged (ConnectionResetError while reading from the self pipe). This fixes the issue by ensuring that we don't attempt to start multiple copies of the self-pipe reading loop. (cherry picked from commit ea5a6363c3f8cc90b7c0cc573922b10f296073b6) Co-authored-by: Ben Darnell <ben@bendarnell.com> Co-authored-by: Ben Darnell <ben@bendarnell.com>
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/proactor_events.py8
-rw-r--r--Lib/asyncio/windows_events.py8
2 files changed, 14 insertions, 2 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 830d8ed..54e4deb 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -766,6 +766,14 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
try:
if f is not None:
f.result() # may raise
+ if self._self_reading_future is not f:
+ # When we scheduled this Future, we assigned it to
+ # _self_reading_future. If it's not there now, something has
+ # tried to cancel the loop while this callback was still in the
+ # queue (see windows_events.ProactorEventLoop.run_forever). In
+ # that case stop here instead of continuing to schedule a new
+ # iteration.
+ return
f = self._proactor.recv(self._ssock, 4096)
except exceptions.CancelledError:
# _close_self_pipe() has been called, stop waiting for data
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py
index 12e87ab..a5ad6fc 100644
--- a/Lib/asyncio/windows_events.py
+++ b/Lib/asyncio/windows_events.py
@@ -318,8 +318,12 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
if self._self_reading_future is not None:
ov = self._self_reading_future._ov
self._self_reading_future.cancel()
- # self_reading_future was just cancelled so it will never be signalled
- # Unregister it otherwise IocpProactor.close will wait for it forever
+ # self_reading_future was just cancelled so if it hasn't been
+ # finished yet, it never will be (it's possible that it has
+ # already finished and its callback is waiting in the queue,
+ # where it could still happen if the event loop is restarted).
+ # Unregister it otherwise IocpProactor.close will wait for it
+ # forever
if ov is not None:
self._proactor._unregister(ov)
self._self_reading_future = None