Skip to content

Commit

Permalink
Handle the socket timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Feb 12, 2024
1 parent bd35572 commit dcbbf87
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/gevent/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,16 @@ def __init__(self, sock=None, keyfile=None, certfile=None,
self.do_handshake_on_connect = do_handshake_on_connect
self.suppress_ragged_eofs = suppress_ragged_eofs
connected = False
sock_timeout = None
if sock is not None:
timeout = sock.gettimeout()
# We're going non-blocking below, can't set timeout yet.
sock_timeout = sock.gettimeout()
socket.__init__(self,
family=sock.family,
type=sock.type,
proto=sock.proto,
fileno=sock.fileno())
self.settimeout(timeout)

# When Python 3 sockets are __del__, they close() themselves,
# including their underlying fd, unless they have been detached.
# Only detach if we succeed in taking ownership; if we raise an exception,
Expand Down Expand Up @@ -331,6 +333,8 @@ def __init__(self, sock=None, keyfile=None, certfile=None,
raise notconn_pre_handshake_data_error
else:
connected = True

self.settimeout(sock_timeout)
self._connected = connected
if connected:
# create the SSL object
Expand Down

0 comments on commit dcbbf87

Please sign in to comment.