Skip to content

Commit 8a3b5d8

Browse files
committed
Explicitly close transport on SSL fingerprint mismatch
1 parent 1a5f3e4 commit 8a3b5d8

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

aiohttp/connector.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -518,23 +518,23 @@ def _create_connection(self, req):
518518
try:
519519
host = hinfo['host']
520520
port = hinfo['port']
521-
conn = yield from self._loop.create_connection(
521+
transp, proto = yield from self._loop.create_connection(
522522
self._factory, host, port,
523523
ssl=sslcontext, family=hinfo['family'],
524524
proto=hinfo['proto'], flags=hinfo['flags'],
525525
server_hostname=hinfo['hostname'] if sslcontext else None)
526-
transport = conn[0]
527-
has_cert = transport.get_extra_info('sslcontext')
526+
has_cert = transp.get_extra_info('sslcontext')
528527
if has_cert and self._fingerprint:
529-
sock = transport.get_extra_info('socket')
528+
sock = transp.get_extra_info('socket')
530529
# gives DER-encoded cert as a sequence of bytes (or None)
531530
cert = sock.getpeercert(binary_form=True)
532531
assert cert
533532
got = self._hashfunc(cert).digest()
534533
expected = self._fingerprint
535534
if got != expected:
535+
transp.close()
536536
raise FingerprintMismatch(expected, got, host, port)
537-
return conn
537+
return transp, proto
538538
except OSError as e:
539539
exc = e
540540
else:

tests/test_connector.py

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def setUp(self):
118118

119119
def tearDown(self):
120120
self.loop.close()
121+
gc.collect()
121122

122123
@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
123124
def test_del(self):

0 commit comments

Comments
 (0)