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):