Skip to content

Commit 97b76b3

Browse files
committed
GH-113280: Fix ResourceWarning in ssl.SSLSocket connected detection
1 parent d71fcde commit 97b76b3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Lib/ssl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ def __init__(self, *args, **kwargs):
804804
@classmethod
805805
def _create(cls, incoming, outgoing, server_side=False,
806806
server_hostname=None, session=None, context=None):
807+
import traceback
808+
traceback.print_stack()
807809
self = cls.__new__(cls)
808810
sslobj = context._wrap_bio(
809811
incoming, outgoing, server_side=server_side,
@@ -1017,6 +1019,7 @@ def _create(cls, sock, server_side=False, do_handshake_on_connect=True,
10171019
self.getpeername()
10181020
except OSError as e:
10191021
if e.errno != errno.ENOTCONN:
1022+
self.close()
10201023
raise
10211024
connected = False
10221025
blocking = self.getblocking()
@@ -1030,6 +1033,7 @@ def _create(cls, sock, server_side=False, do_handshake_on_connect=True,
10301033
except OSError as e:
10311034
# EINVAL occurs for recv(1) on non-connected on unix sockets.
10321035
if e.errno not in (errno.ENOTCONN, errno.EINVAL):
1036+
self.close()
10331037
raise
10341038
notconn_pre_handshake_data = b''
10351039
self.setblocking(blocking)

0 commit comments

Comments
 (0)