@@ -1202,12 +1202,13 @@ def test_create_server_ssl_verify_failed(self):
12021202 '(?i)certificate.verify.failed' ):
12031203 self .loop .run_until_complete (f_c )
12041204
1205- # execute the loop to log the connection error
1206- test_utils .run_briefly (self .loop )
1205+ # close connection: wait until the server-side transport of the
1206+ # failed handshake is closed as well, otherwise its socket may
1207+ # still be open when the loop is closed (gh-159123).
1208+ server .close ()
1209+ self .loop .run_until_complete (server .wait_closed ())
12071210
1208- # close connection
12091211 self .assertIsNone (proto .transport )
1210- server .close ()
12111212
12121213 @socket_helper .skip_unless_bind_unix_socket
12131214 @unittest .skipIf (ssl is None , 'No ssl module' )
@@ -1232,12 +1233,13 @@ def test_create_unix_server_ssl_verify_failed(self):
12321233 '(?i)certificate.verify.failed' ):
12331234 self .loop .run_until_complete (f_c )
12341235
1235- # execute the loop to log the connection error
1236- test_utils .run_briefly (self .loop )
1236+ # close connection: wait until the server-side transport of the
1237+ # failed handshake is closed as well, otherwise its socket may
1238+ # still be open when the loop is closed (gh-159123).
1239+ server .close ()
1240+ self .loop .run_until_complete (server .wait_closed ())
12371241
1238- # close connection
12391242 self .assertIsNone (proto .transport )
1240- server .close ()
12411243
12421244 @unittest .skipIf (ssl is None , 'No ssl module' )
12431245 def test_create_server_ssl_match_failed (self ):
@@ -1268,10 +1270,14 @@ def test_create_server_ssl_match_failed(self):
12681270 with self .assertRaisesRegex (ssl .CertificateError , regex ):
12691271 self .loop .run_until_complete (f_c )
12701272
1271- # close connection
1273+ # close connection: wait until the server-side transport of the
1274+ # failed handshake is closed as well, otherwise its socket may
1275+ # still be open when the loop is closed (gh-159123).
1276+ server .close ()
1277+ self .loop .run_until_complete (server .wait_closed ())
1278+
12721279 # transport is None because TLS ALERT aborted the handshake
12731280 self .assertIsNone (proto .transport )
1274- server .close ()
12751281
12761282 @socket_helper .skip_unless_bind_unix_socket
12771283 @unittest .skipIf (ssl is None , 'No ssl module' )
0 commit comments