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

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

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 3d7be767a8bb29..7d07cb245bcc17 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -3093,6 +3093,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