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