Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set an explicit timeout on SSL handshake to prevent hangs #398

Merged
merged 1 commit into from Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions amqp/transport.py
Expand Up @@ -401,6 +401,8 @@ def __init__(self, host, connect_timeout=None, ssl=None, **kwargs):
def _setup_transport(self):
"""Wrap the socket in an SSL object."""
self.sock = self._wrap_socket(self.sock, **self.sslopts)
# Explicitly set a timeout here to stop any hangs on handshake.
self.sock.settimeout(self.connect_timeout)
self.sock.do_handshake()
self._quick_recv = self.sock.read

Expand Down
8 changes: 8 additions & 0 deletions t/unit/test_transport.py
Expand Up @@ -864,6 +864,14 @@ def test_read_SSLError(self):
with pytest.raises(socket.timeout):
self.t._read(64)

def test_handshake_timeout(self):
self.t.sock = Mock()
self.t._wrap_socket = Mock()
self.t._wrap_socket.return_value = self.t.sock
self.t.sock.do_handshake.side_effect = socket.timeout()
with pytest.raises(socket.timeout):
self.t._setup_transport()


class test_TCPTransport:
class Transport(transport.TCPTransport):
Expand Down