Skip to content

Commit 00713d8

Browse files
committed
Fix connection shutdown delay on invalid fingerprint on PyPy
This is not a security issue because the Python code sees the underlying socket as closed, but it fails irctest's testUntrustedCertificate because the connection is left open longer than necessary
1 parent e858d36 commit 00713d8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/utils/net.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,15 @@ def ssl_wrap_socket(conn, hostname, logger, certfile=None,
192192
conn = context.wrap_socket(conn, server_hostname=hostname)
193193

194194
if trusted_fingerprints:
195-
check_certificate_fingerprint(conn, trusted_fingerprints)
195+
try:
196+
check_certificate_fingerprint(conn, trusted_fingerprints)
197+
except:
198+
# We need to explicitly close the SSL wrapper here, because we
199+
# don't return it to the caller.
200+
# Without it, current PyPy versions won't close the underlying
201+
# socket until this wrapper gets garbage-collected.
202+
conn.close()
203+
raise
196204

197205
return conn
198206

0 commit comments

Comments
 (0)