[Python-checkins] bpo-43842: Fix race condition in test_logging SMTP test (GH-25436) (GH-25437)
vstinner
webhook-mailer at python.org
Fri Apr 16 10:06:47 EDT 2021
https://github.com/python/cpython/commit/e1903e11a3d42512effe336026e0c67f602e5848
commit: e1903e11a3d42512effe336026e0c67f602e5848
branch: 3.9
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-04-16T16:06:38+02:00
summary:
bpo-43842: Fix race condition in test_logging SMTP test (GH-25436) (GH-25437)
Fix a race condition in the SMTP test of test_logging. Don't close a
file descriptor (socket) from a different thread while
asyncore.loop() is polling the file descriptor.
(cherry picked from commit 75ec103b3adbb7c619a0e22fa60f3d34c5a9e603)
files:
A Misc/NEWS.d/next/Tests/2021-04-16-14-07-40.bpo-43842.w60GAH.rst
M Lib/test/test_logging.py
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index a6cd291c9a553..1760e241d824c 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -826,6 +826,7 @@ def __init__(self, addr, handler, poll_interval, sockmap):
self.port = self.socket.getsockname()[1]
self._handler = handler
self._thread = None
+ self._quit = False
self.poll_interval = poll_interval
def process_message(self, peer, mailfrom, rcpttos, data):
@@ -857,16 +858,18 @@ def serve_forever(self, poll_interval):
:func:`select` or :func:`poll` call by
:func:`asyncore.loop`.
"""
- asyncore.loop(poll_interval, map=self._map)
+ while not self._quit:
+ asyncore.loop(poll_interval, map=self._map, count=1)
def stop(self):
"""
Stop the thread by closing the server instance.
Wait for the server thread to terminate.
"""
- self.close()
+ self._quit = True
support.join_thread(self._thread)
self._thread = None
+ self.close()
asyncore.close_all(map=self._map, ignore_all=True)
diff --git a/Misc/NEWS.d/next/Tests/2021-04-16-14-07-40.bpo-43842.w60GAH.rst b/Misc/NEWS.d/next/Tests/2021-04-16-14-07-40.bpo-43842.w60GAH.rst
new file mode 100644
index 0000000000000..5b4a120eb8637
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2021-04-16-14-07-40.bpo-43842.w60GAH.rst
@@ -0,0 +1,4 @@
+Fix a race condition in the SMTP test of test_logging. Don't close a file
+descriptor (socket) from a different thread while asyncore.loop() is polling
+the file descriptor.
+Patch by Victor Stinner.
More information about the Python-checkins
mailing list