diff options
author | James E. Blair <jim@acmegating.com> | 2022-02-01 09:07:41 -0800 |
---|---|---|
committer | James E. Blair <jim@acmegating.com> | 2022-02-01 09:07:41 -0800 |
commit | 00fdf4542b3f058816184dc8ff62ee2af1cdd4ce (patch) | |
tree | b0fc9b3bd0b3304bb7aea30bf25aaedc3aad2c7c | |
parent | 930ee8faa3076233614565fcfbf55a4ee74551a7 (diff) | |
download | zuul-00fdf4542b3f058816184dc8ff62ee2af1cdd4ce.tar.gz |
Add ssh connection timeout
In case a network problem causes the socket connection to establish
slowly, set a socket timeout of 30 seconds (matching the HTTP request
timeout).
Change-Id: Idd2e29d019357963faa25f834289cf6f318aa720
-rw-r--r-- | zuul/driver/gerrit/gerritconnection.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py index 18f31c189..41d1dc2af 100644 --- a/zuul/driver/gerrit/gerritconnection.py +++ b/zuul/driver/gerrit/gerritconnection.py @@ -54,6 +54,8 @@ from zuul.zk.event_queues import ConnectionEventQueue, EventReceiverElection # HTTP timeout in seconds TIMEOUT = 30 +# SSH connection timeout +SSH_TIMEOUT = TIMEOUT # commentSizeLimit default set by Gerrit. Gerrit is a bit # vague about what this means, it says @@ -405,10 +407,13 @@ class GerritWatcher(threading.Thread): client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.WarningPolicy()) + # SSH banner, handshake, and auth timeouts default to 15 + # seconds, so we only set the socket timeout here. client.connect(self.hostname, username=self.username, port=self.port, - key_filename=self.keyfile) + key_filename=self.keyfile, + timeout=SSH_TIMEOUT) transport = client.get_transport() transport.set_keepalive(self.keepalive) @@ -1469,10 +1474,13 @@ class GerritConnection(ZKChangeCacheMixin, ZKBranchCacheMixin, BaseConnection): client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.WarningPolicy()) + # SSH banner, handshake, and auth timeouts default to 15 + # seconds, so we only set the socket timeout here. client.connect(self.server, username=self.user, port=self.port, - key_filename=self.keyfile) + key_filename=self.keyfile, + timeout=SSH_TIMEOUT) transport = client.get_transport() transport.set_keepalive(self.keepalive) self.client = client |