Skip to content

Commit 0eba7c3

Browse files
authored
bpo-33789: test_asyncio: Fix ResourceWarning (GH-7460)
* Close sockets and streams to fix ResourceWarning warnings * Catch also OSError to hide a traceback on an expected handshake error
1 parent 3ef769f commit 0eba7c3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Lib/test/test_asyncio/functional.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,14 @@ def start_tls(self, ssl_context, *,
150150
server_hostname=server_hostname,
151151
do_handshake_on_connect=False)
152152

153-
ssl_sock.do_handshake()
153+
try:
154+
ssl_sock.do_handshake()
155+
except:
156+
ssl_sock.close()
157+
raise
158+
finally:
159+
self.__sock.close()
154160

155-
self.__sock.close()
156161
self.__sock = ssl_sock
157162

158163
def __getattr__(self, name):

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ def server(sock):
604604
server_side=True)
605605
except ssl.SSLError:
606606
pass
607+
except OSError:
608+
pass
607609
finally:
608610
sock.close()
609611

@@ -640,6 +642,7 @@ def server(sock):
640642
except ssl.SSLError:
641643
pass
642644
finally:
645+
orig_sock.close()
643646
sock.close()
644647

645648
async def client(addr):
@@ -653,6 +656,8 @@ async def client(addr):
653656
writer.write(b'B')
654657
with self.assertRaises(ssl.SSLError):
655658
await reader.readline()
659+
660+
writer.close()
656661
return 'OK'
657662

658663
with self.tcp_server(server,

0 commit comments

Comments
 (0)