mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
471870fc50
commit
75ec103b3a
2 changed files with 9 additions and 2 deletions
|
@ -829,6 +829,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):
|
||||
|
@ -860,16 +861,18 @@ 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):
|
||||
"""
|
||||
Stop the thread by closing the server instance.
|
||||
Wait for the server thread to terminate.
|
||||
"""
|
||||
self.close()
|
||||
self._quit = True
|
||||
threading_helper.join_thread(self._thread)
|
||||
self._thread = None
|
||||
self.close()
|
||||
asyncore.close_all(map=self._map, ignore_all=True)
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue