Skip to content

Commit 75ec103

Browse files
authored
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.
1 parent 471870f commit 75ec103

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
@@ -829,6 +829,7 @@ def __init__(self, addr, handler, poll_interval, sockmap):
829829
self.port = self.socket.getsockname()[1]
830830
self._handler = handler
831831
self._thread = None
832+
self._quit = False
832833
self.poll_interval = poll_interval
833834

834835
def process_message(self, peer, mailfrom, rcpttos, data):
@@ -860,16 +861,18 @@ def serve_forever(self, poll_interval):
860861
:func:`select` or :func:`poll` call by
861862
:func:`asyncore.loop`.
862863
"""
863-
asyncore.loop(poll_interval, map=self._map)
864+
while not self._quit:
865+
asyncore.loop(poll_interval, map=self._map, count=1)
864866

865867
def stop(self):
866868
"""
867869
Stop the thread by closing the server instance.
868870
Wait for the server thread to terminate.
869871
"""
870-
self.close()
872+
self._quit = True
871873
threading_helper.join_thread(self._thread)
872874
self._thread = None
875+
self.close()
873876
asyncore.close_all(map=self._map, ignore_all=True)
874877

875878

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)