MCPcopy Index your code
hub / github.com/python/cpython / test_thread_recv_while_main_thread_sends

Method test_thread_recv_while_main_thread_sends

Lib/test/test_ssl.py:4966–5000  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4964 s.connect((HOST, server.port))
4965
4966 def test_thread_recv_while_main_thread_sends(self):
4967 # GH-137583: Locking was added to calls to send() and recv() on SSL
4968 # socket objects. This seemed fine at the surface level because those
4969 # calls weren't re-entrant, but recv() calls would implicitly mimick
4970 # holding a lock by blocking until it received data. This means that
4971 # if a thread started to infinitely block until data was received, calls
4972 # to send() would deadlock, because it would wait forever on the lock
4973 # that the recv() call held.
4974 data = b"1" * 1024
4975 event = threading.Event()
4976 def background(sock):
4977 event.set()
4978 received = sock.recv(len(data))
4979 self.assertEqual(received, data)
4980
4981 client_context, server_context, hostname = testing_context()
4982 server = ThreadedEchoServer(context=server_context)
4983 with server:
4984 with client_context.wrap_socket(socket.socket(),
4985 server_hostname=hostname) as sock:
4986 sock.connect((HOST, server.port))
4987 sock.settimeout(1)
4988 sock.setblocking(1)
4989 # Ensure that the server is ready to accept requests
4990 sock.sendall(b"123")
4991 self.assertEqual(sock.recv(3), b"123")
4992 with threading_helper.catch_threading_exception() as cm:
4993 thread = threading.Thread(target=background,
4994 args=(sock,), daemon=True)
4995 thread.start()
4996 event.wait()
4997 sock.sendall(data)
4998 thread.join()
4999 if cm.exc_value is not None:
5000 raise cm.exc_value
5001
5002
5003@unittest.skipUnless(has_tls_version('TLSv1_3') and ssl.HAS_PHA,

Callers

nothing calls this directly

Calls 14

startMethod · 0.95
waitMethod · 0.95
joinMethod · 0.95
testing_contextFunction · 0.85
ThreadedEchoServerClass · 0.85
EventMethod · 0.80
wrap_socketMethod · 0.80
socketMethod · 0.80
connectMethod · 0.45
settimeoutMethod · 0.45
setblockingMethod · 0.45
sendallMethod · 0.45

Tested by

no test coverage detected