bpo-39010: Fix errors logged on proactor loop restart (GH-22017) (#22034)

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 ea5a6363c3)

Co-authored-by: Ben Darnell <ben@bendarnell.com>

Co-authored-by: Ben Darnell <ben@bendarnell.com>
This commit is contained in:
Miss Islington (bot) 2020-09-03 12:38:29 -07:00 committed by GitHub
parent 270e249290
commit 49571c0b0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 2 deletions

View file

@ -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):