Skip to content

Commit 816da33

Browse files
authored
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 75ec103) (cherry picked from commit e1903e1)
1 parent 582917f commit 816da33

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Lib/test/test_logging.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ def __init__(self, addr, handler, poll_interval, sockmap):
836836
self.port = self.socket.getsockname()[1]
837837
self._handler = handler
838838
self._thread = None
839+
self._quit = False
839840
self.poll_interval = poll_interval
840841

841842
def process_message(self, peer, mailfrom, rcpttos, data):
@@ -867,7 +868,8 @@ def serve_forever(self, poll_interval):
867868
:func:`select` or :func:`poll` call by
868869
:func:`asyncore.loop`.
869870
"""
870-
asyncore.loop(poll_interval, map=self._map)
871+
while not self._quit:
872+
asyncore.loop(poll_interval, map=self._map, count=1)
871873

872874
def stop(self, timeout=None):
873875
"""
@@ -877,9 +879,10 @@ def stop(self, timeout=None):
877879
:param timeout: How long to wait for the server thread
878880
to terminate.
879881
"""
880-
self.close()
882+
self._quit = True
881883
support.join_thread(self._thread, timeout)
882884
self._thread = None
885+
self.close()
883886
asyncore.close_all(map=self._map, ignore_all=True)
884887

885888

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a race condition in the SMTP test of test_logging. Don't close a file
2+
descriptor (socket) from a different thread while asyncore.loop() is polling
3+
the file descriptor.
4+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)