Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-43842: Fix race condition in test_logging SMTP test (GH-25436)
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 75ec103)
  • Loading branch information
vstinner committed Apr 16, 2021
commit 65b1731ec18e47a6d414dd47aadc3ddecf84de97
7 changes: 5 additions & 2 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
@@ -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.