Skip to content

Commit 42a0351

Browse files
committed
Fix the test.
1 parent 0a070e2 commit 42a0351

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,20 +4628,24 @@ def test_thread_recv_while_main_thread_sends(self):
46284628
# if a thread started to infinitely block until data was received, calls
46294629
# to send() would deadlock, because it would wait forever on the lock
46304630
# that the recv() call held.
4631-
data = b"A" * 5000
4631+
data = b"a" * 500
46324632
def background(sock):
4633-
received = sock.recv(5000)
4634-
assert received == data
4633+
received = sock.recv(500)
4634+
self.assertEqual(received, data)
46354635

4636-
client_context, server_context, _ = testing_context()
4636+
client_context, server_context, hostname = testing_context()
46374637
server = ThreadedEchoServer(context=server_context)
46384638
with server:
4639-
with client_context.wrap_socket(socket.socket()) as sock:
4639+
with client_context.wrap_socket(socket.socket(),
4640+
server_hostname=hostname) as sock:
46404641
sock.connect((HOST, server.port))
4641-
thread = threading.Thread(target=background, args=(sock,))
4642-
thread.start()
4643-
sock.sendall(data)
4644-
4642+
with threading_helper.catch_threading_exception() as cm:
4643+
thread = threading.Thread(target=background, args=(sock,))
4644+
thread.start()
4645+
sock.sendall(data)
4646+
thread.join()
4647+
if cm.exc_value is not None:
4648+
raise cm.exc_value
46454649

46464650
@unittest.skipUnless(has_tls_version('TLSv1_3') and ssl.HAS_PHA,
46474651
"Test needs TLS 1.3 PHA")

Modules/_ssl.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,6 @@ typedef struct {
366366
* and shutdown methods check for chained exceptions.
367367
*/
368368
PyObject *exc;
369-
/* Lock to synchronize calls when the thread state is detached.
370-
See also gh-134698. */
371-
PyMutex tstate_mutex;
372369
} PySSLSocket;
373370

374371
#define PySSLSocket_CAST(op) ((PySSLSocket *)(op))
@@ -918,7 +915,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
918915
self->server_hostname = NULL;
919916
self->err = err;
920917
self->exc = NULL;
921-
self->tstate_mutex = (PyMutex){0};
922918

923919
/* Make sure the SSL error state is initialized */
924920
ERR_clear_error();

Modules/_ssl/debughelpers.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
140140
* critical debug helper.
141141
*/
142142

143-
assert(PyMutex_IsLocked(&ssl_obj->tstate_mutex));
144143
Py_BEGIN_ALLOW_THREADS
145144
PyThread_acquire_lock(lock, 1);
146145
res = BIO_printf(ssl_obj->ctx->keylog_bio, "%s\n", line);

0 commit comments

Comments
 (0)