From e4cc502e1638981053a9f9a5fdff595a8c3f4c23 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Fri, 30 Oct 2026 07:46:19 +0100 Subject: [PATCH] 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 Co-authored-by: Claude Opus 5.5 --- Lib/test/test_socket.py | 3 +++ 1 file changed, 3 insertions(+) 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):