Set keepalives for gerrit connections
Some gerrit clients connect through stateful firewalls, which are occasionally "flushed", which leads to hanging of the connection. This could be avoided by tcp keepalives. To turn keepalives on, set "keepalive" in gerrit connection attributes to non-zero (0 means no keepalives sent) The default is turn it on with timeout of 60 seconds. Change-Id: Ic3d11e0ac2108f02832e2114ba8bc1adcc87cb4f
This commit is contained in:
parent
4c51d9c6da
commit
9f0a3229f7
|
@ -38,6 +38,9 @@ Create a connection with gerrit.
|
|||
Path to SSH key to use when logging into above server.
|
||||
``sshkey=/home/zuul/.ssh/id_rsa``
|
||||
|
||||
**keepalive**
|
||||
Optional: Keepalive timeout, 0 means no keepalive.
|
||||
``keepalive=60``
|
||||
|
||||
Gerrit Configuration
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -32,6 +32,7 @@ server=review.example.com
|
|||
;baseurl=https://review.example.com/r
|
||||
user=jenkins
|
||||
sshkey=/home/jenkins/.ssh/id_rsa
|
||||
;keepalive=60
|
||||
|
||||
[connection smtp]
|
||||
driver=smtp
|
||||
|
|
|
@ -135,13 +135,14 @@ class GerritWatcher(threading.Thread):
|
|||
poll_timeout = 500
|
||||
|
||||
def __init__(self, gerrit_connection, username, hostname, port=29418,
|
||||
keyfile=None):
|
||||
keyfile=None, keepalive=60):
|
||||
threading.Thread.__init__(self)
|
||||
self.username = username
|
||||
self.keyfile = keyfile
|
||||
self.hostname = hostname
|
||||
self.port = port
|
||||
self.gerrit_connection = gerrit_connection
|
||||
self.keepalive = keepalive
|
||||
self._stopped = False
|
||||
|
||||
def _read(self, fd):
|
||||
|
@ -172,6 +173,8 @@ class GerritWatcher(threading.Thread):
|
|||
username=self.username,
|
||||
port=self.port,
|
||||
key_filename=self.keyfile)
|
||||
transport = client.get_transport()
|
||||
transport.set_keepalive(self.keepalive)
|
||||
|
||||
stdin, stdout, stderr = client.exec_command("gerrit stream-events")
|
||||
|
||||
|
@ -224,6 +227,7 @@ class GerritConnection(BaseConnection):
|
|||
self.server = self.connection_config.get('server')
|
||||
self.port = int(self.connection_config.get('port', 29418))
|
||||
self.keyfile = self.connection_config.get('sshkey', None)
|
||||
self.keepalive = int(self.connection_config.get('keepalive', 60))
|
||||
self.watcher_thread = None
|
||||
self.event_queue = None
|
||||
self.client = None
|
||||
|
@ -356,6 +360,8 @@ class GerritConnection(BaseConnection):
|
|||
username=self.user,
|
||||
port=self.port,
|
||||
key_filename=self.keyfile)
|
||||
transport = client.get_transport()
|
||||
transport.set_keepalive(self.keepalive)
|
||||
self.client = client
|
||||
|
||||
def _ssh(self, command, stdin_data=None):
|
||||
|
@ -461,7 +467,8 @@ class GerritConnection(BaseConnection):
|
|||
self.user,
|
||||
self.server,
|
||||
self.port,
|
||||
keyfile=self.keyfile)
|
||||
keyfile=self.keyfile,
|
||||
keepalive=self.keepalive)
|
||||
self.watcher_thread.start()
|
||||
|
||||
def _stop_event_connector(self):
|
||||
|
|
Loading…
Reference in New Issue