Skip to content

Commit 79b81d1

Browse files
[3.11] gh-76106: Remove the cleanup lock in test_socket (GH-110539) (GH-110700)
It does not already work (because it locks only addCleanup(), not doCleanups()), and it is no longer needed since the clean up procedure waits for all test threads to join. (cherry picked from commit f27b830) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent a8b2d12 commit 79b81d1

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

Lib/test/test_socket.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,26 +201,6 @@ def setUp(self):
201201
self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
202202
self.port = socket_helper.bind_port(self.serv)
203203

204-
class ThreadSafeCleanupTestCase:
205-
"""Subclass of unittest.TestCase with thread-safe cleanup methods.
206-
207-
This subclass protects the addCleanup() method with a recursive lock.
208-
209-
doCleanups() is called when the server completed, but the client can still
210-
be running in its thread especially if the server failed with a timeout.
211-
Don't put a lock on doCleanups() to prevent deadlock between addCleanup()
212-
called in the client and doCleanups() waiting for self.done.wait of
213-
ThreadableTest._setUp() (gh-110167)
214-
"""
215-
216-
def __init__(self, *args, **kwargs):
217-
super().__init__(*args, **kwargs)
218-
self._cleanup_lock = threading.RLock()
219-
220-
def addCleanup(self, *args, **kwargs):
221-
with self._cleanup_lock:
222-
return super().addCleanup(*args, **kwargs)
223-
224204

225205
class SocketCANTest(unittest.TestCase):
226206

@@ -613,8 +593,7 @@ def setUp(self):
613593
self.serv.listen()
614594

615595

616-
class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase,
617-
ThreadableTest):
596+
class ThreadedSocketTestMixin(SocketTestBase, ThreadableTest):
618597
"""Mixin to add client socket and allow client/server tests.
619598
620599
Client socket is self.cli and its address is self.cli_addr. See
@@ -2698,7 +2677,7 @@ def _testRecvFromNegative(self):
26982677
# here assumes that datagram delivery on the local machine will be
26992678
# reliable.
27002679

2701-
class SendrecvmsgBase(ThreadSafeCleanupTestCase):
2680+
class SendrecvmsgBase:
27022681
# Base class for sendmsg()/recvmsg() tests.
27032682

27042683
# Time in seconds to wait before considering a test failed, or
@@ -4564,7 +4543,6 @@ def testInterruptedRecvmsgIntoTimeout(self):
45644543
@unittest.skipUnless(hasattr(signal, "alarm") or hasattr(signal, "setitimer"),
45654544
"Don't have signal.alarm or signal.setitimer")
45664545
class InterruptedSendTimeoutTest(InterruptedTimeoutBase,
4567-
ThreadSafeCleanupTestCase,
45684546
SocketListeningTestMixin, TCPTestBase):
45694547
# Test interrupting the interruptible send*() methods with signals
45704548
# when a timeout is set.

0 commit comments

Comments
 (0)