From ca1bbd892438b719b0a4c5db11201a26ecf13ff9 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 29 Oct 2026 22:38:04 +0100 Subject: [PATCH] gh-160561: Fix race in test_socket testFromFdError 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 --- 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 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):