@@ -5197,6 +5197,36 @@ def test_got_eof(self):
51975197
51985198 self .assertEqual (sslsock .pending (), 0 )
51995199
5200+ def test_oserror_does_not_leak_to_other_sockets (self ):
5201+ # gh-158313: An OSError for one connection must not stay on the
5202+ # thread's OpenSSL error queue and be raised for another connection.
5203+ client_context , server_context , hostname = testing_context ()
5204+ server_context .num_tickets = 0
5205+
5206+ def connect ():
5207+ csock , ssock = socket .socketpair ()
5208+ client = client_context .wrap_socket (
5209+ csock , server_hostname = hostname , do_handshake_on_connect = False )
5210+ server = server_context .wrap_socket (
5211+ ssock , server_side = True , do_handshake_on_connect = False )
5212+ thread = threading .Thread (target = server .do_handshake )
5213+ thread .start ()
5214+ client .do_handshake ()
5215+ thread .join ()
5216+ return client , server
5217+
5218+ client , server = connect ()
5219+ client2 , server2 = connect ()
5220+ with client , server , client2 , server2 :
5221+ server .close ()
5222+ client .settimeout (support .SHORT_TIMEOUT )
5223+ with self .assertRaises (OSError ):
5224+ while True :
5225+ client .send (b'x' * 1024 )
5226+
5227+ client2 .setblocking (False )
5228+ self .assertRaises (ssl .SSLWantReadError , client2 .recv , 1 )
5229+
52005230
52015231@unittest .skipUnless (has_tls_version ('TLSv1_3' ) and ssl .HAS_PHA ,
52025232 "Test needs TLS 1.3 PHA" )
0 commit comments