diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-09-03 19:38:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 19:38:34 (GMT) |
commit | a986b061a3cd4661eb9f857e2936291f1847bd15 (patch) | |
tree | 140f444860fd00133352196aca55a6a3c1fa0c9a /Lib/test | |
parent | 9fef7c54a0adfade5ec94259d97f22e05fe9e3e3 (diff) | |
download | cpython-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/test')
-rw-r--r-- | Lib/test/test_asyncio/test_proactor_events.py | 1 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_windows_events.py | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index 007039a..e4809c3 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -736,6 +736,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase): def test_loop_self_reading_fut(self): fut = mock.Mock() + self.loop._self_reading_future = fut self.loop._loop_self_reading(fut) self.assertTrue(fut.result.called) self.proactor.recv.assert_called_with(self.ssock, 4096) diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index 6b00570..33388a8 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -211,6 +211,26 @@ class ProactorTests(test_utils.TestCase): fut.cancel() fut.cancel() + def test_read_self_pipe_restart(self): + # Regression test for https://bugs.python.org/issue39010 + # Previously, restarting a proactor event loop in certain states + # would lead to spurious ConnectionResetErrors being logged. + self.loop.call_exception_handler = mock.Mock() + # Start an operation in another thread so that the self-pipe is used. + # This is theoretically timing-dependent (the task in the executor + # must complete before our start/stop cycles), but in practice it + # seems to work every time. + f = self.loop.run_in_executor(None, lambda: None) + self.loop.stop() + self.loop.run_forever() + self.loop.stop() + self.loop.run_forever() + # If we don't wait for f to complete here, we may get another + # warning logged about a thread that didn't shut down cleanly. + self.loop.run_until_complete(f) + self.loop.close() + self.assertFalse(self.loop.call_exception_handler.called) + class WinPolicyTests(test_utils.TestCase): |