diff options
author | Victor Stinner <vstinner@python.org> | 2021-04-16 14:37:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-16 14:37:09 (GMT) |
commit | 816da333c8ee848dab7c830c561b8df0b8d23915 (patch) | |
tree | 975d1145f63da03383712398665db68be5c119e1 | |
parent | 582917f8b255801f3c722d89ff2b8d6b17a11590 (diff) | |
download | cpython-816da333c8ee848dab7c830c561b8df0b8d23915.zip cpython-816da333c8ee848dab7c830c561b8df0b8d23915.tar.gz cpython-816da333c8ee848dab7c830c561b8df0b8d23915.tar.bz2 |
bpo-43842: Fix race condition in test_logging SMTP test (GH-25436) (GH-25437) (GH-25440)
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)
(cherry picked from commit e1903e11a3d42512effe336026e0c67f602e5848)
-rw-r--r-- | Lib/test/test_logging.py | 7 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2021-04-16-14-07-40.bpo-43842.w60GAH.rst | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 3e15db0..15250a3 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -836,6 +836,7 @@ class TestSMTPServer(smtpd.SMTPServer): 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): @@ -867,7 +868,8 @@ class TestSMTPServer(smtpd.SMTPServer): :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, timeout=None): """ @@ -877,9 +879,10 @@ class TestSMTPServer(smtpd.SMTPServer): :param timeout: How long to wait for the server thread to terminate. """ - self.close() + self._quit = True support.join_thread(self._thread, timeout) 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 0000000..5b4a120 --- /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. |