https://github.com/python/cpython/commit/1bbe7e962876c2349d78b2df2a0c5d960e3c2da4
commit: 1bbe7e962876c2349d78b2df2a0c5d960e3c2da4
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: asvetlov <[email protected]>
date: 2026-10-30T08:28:24+01:00
summary:

[3.15] gh-160561: Fix race in test_socket testFromFdError (GH-160930) (#160955)

gh-160561: Fix race in test_socket testFromFdError (GH-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.
(cherry picked from commit af79f49308f8f87896d1c09419db3f5ff67185af)

Co-authored-by: Andrew Svetlov <[email protected]>
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 5609244b2b7976..b889034c0efd2f 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -3178,6 +3178,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