https://github.com/python/cpython/commit/af79f49308f8f87896d1c09419db3f5ff67185af
commit: af79f49308f8f87896d1c09419db3f5ff67185af
branch: main
author: Andrew Svetlov <[email protected]>
committer: asvetlov <[email protected]>
date: 2026-10-30T07:46:19+01:00
summary:

gh-160561: Fix race in test_socket testFromFdError (#160930)

The client thread closes its socket in clientTearDown() concurrently
with the server-side test, so the process-wide fd count could drop
between the two os_helper.fd_count() calls.  Wait for the client thread
to finish before taking the first count.

Co-authored-by: Claude Opus 5.5 <[email protected]>

files:
M Lib/test/test_socket.py

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index b37925af1e2d0f..bb0cfe7502f2ab 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -3231,6 +3231,9 @@ def _testFromFd(self):
     def testFromFdError(self):
         # Make sure that the fromfd() duplicated socket is closed on error.
         fd = self.cli_conn.fileno()
+        # Wait for the client thread to close its socket, otherwise
+        # fd_count() can race with clientTearDown().
+        self.done.wait()
         fd_count_before = os_helper.fd_count()
 
         with self.assertRaises(TypeError):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to