Skip to content

Commit e1903e1

Browse files
authored
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 75ec103)
1 parent 56c76df commit e1903e1

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
@@ -826,6 +826,7 @@ def __init__(self, addr, handler, poll_interval, sockmap):
826826
self.port = self.socket.getsockname()[1]
827827
self._handler = handler
828828
self._thread = None
829+
self._quit = False
829830
self.poll_interval = poll_interval
830831

831832
def process_message(self, peer, mailfrom, rcpttos, data):
@@ -857,16 +858,18 @@ def serve_forever(self, poll_interval):
857858
:func:`select` or :func:`poll` call by
858859
:func:`asyncore.loop`.
859860
"""
860-
asyncore.loop(poll_interval, map=self._map)
861+
while not self._quit:
862+
asyncore.loop(poll_interval, map=self._map, count=1)
861863

862864
def stop(self):
863865
"""
864866
Stop the thread by closing the server instance.
865867
Wait for the server thread to terminate.
866868
"""
867-
self.close()
869+
self._quit = True
868870
support.join_thread(self._thread)
869871
self._thread = None
872+
self.close()
870873
asyncore.close_all(map=self._map, ignore_all=True)
871874

872875

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)