summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-05 19:18:44 (GMT)
committerGitHub <noreply@github.com>2023-10-05 19:18:44 (GMT)
commit8da3367067f3e22d2369a00640185525813520fb (patch)
tree7352dabeb356b61006900843731fdf7138922c2d /Lib/test/test_socket.py
parent8394368f1fce672ad25af512063a0f8f5d8a08f9 (diff)
downloadcpython-8da3367067f3e22d2369a00640185525813520fb.zip
cpython-8da3367067f3e22d2369a00640185525813520fb.tar.gz
cpython-8da3367067f3e22d2369a00640185525813520fb.tar.bz2
[3.11] gh-110167: Fix test_socket deadlock in doCleanups() (GH-110416) (#110424)
gh-110167: Fix test_socket deadlock in doCleanups() (GH-110416) Fix a deadlock in test_socket when server fails with a timeout but the client is still running in its thread. Don't hold a lock to call cleanup functions in doCleanups(). One of the cleanup function waits until the client completes, whereas the client could deadlock if it called addCleanup() in such situation. doCleanups() is called when the server completed, but the client can still be running in its thread especially if the server failed with a timeout. Don't put a lock on doCleanups() to prevent deadlock between addCleanup() called in the client and doCleanups() waiting for self.done.wait of ThreadableTest._setUp(). (cherry picked from commit 318f5df27109ff8d2519edefa771920a0ec62b92) Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 190efb4..bc93d99 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -204,8 +204,13 @@ class SocketUDPLITETest(SocketUDPTest):
class ThreadSafeCleanupTestCase:
"""Subclass of unittest.TestCase with thread-safe cleanup methods.
- This subclass protects the addCleanup() and doCleanups() methods
- with a recursive lock.
+ This subclass protects the addCleanup() method with a recursive lock.
+
+ doCleanups() is called when the server completed, but the client can still
+ be running in its thread especially if the server failed with a timeout.
+ Don't put a lock on doCleanups() to prevent deadlock between addCleanup()
+ called in the client and doCleanups() waiting for self.done.wait of
+ ThreadableTest._setUp() (gh-110167)
"""
def __init__(self, *args, **kwargs):
@@ -216,9 +221,6 @@ class ThreadSafeCleanupTestCase:
with self._cleanup_lock:
return super().addCleanup(*args, **kwargs)
- def doCleanups(self, *args, **kwargs):
- with self._cleanup_lock:
- return super().doCleanups(*args, **kwargs)
class SocketCANTest(unittest.TestCase):