summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbderrahim Kitouni <akitouni@gnome.org>2020-07-02 10:37:33 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2020-07-30 14:41:20 +0000
commit75b8cff0d022001904c38caf1f7e701cf9995e10 (patch)
tree2f5d976c6deaa0f43dce2e434bb7bf42cce78b90
parent0ff177595e710ade7f79fe2fa7dff44167b8b324 (diff)
downloadbuildstream-75b8cff0d022001904c38caf1f7e701cf9995e10.tar.gz
cascache.py: enable grpc keepalive pings
This allows bst to detect when connections are dropped instead of hanging indefinitely
-rw-r--r--buildstream/_artifactcache/cascache.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/buildstream/_artifactcache/cascache.py b/buildstream/_artifactcache/cascache.py
index c6efcf508..645f2dad7 100644
--- a/buildstream/_artifactcache/cascache.py
+++ b/buildstream/_artifactcache/cascache.py
@@ -41,6 +41,9 @@ from .._exceptions import CASError
# Limit payload to 1 MiB to leave sufficient headroom for metadata.
_MAX_PAYLOAD_BYTES = 1024 * 1024
+# How often is a keepalive ping sent to the server to make sure the transport is still alive
+_KEEPALIVE_TIME_MS = 60000
+
class _Attempt():
@@ -1012,7 +1015,8 @@ class CASRemote():
url = urlparse(self.spec.url)
if url.scheme == 'http':
port = url.port or 80
- self.channel = grpc.insecure_channel('{}:{}'.format(url.hostname, port))
+ self.channel = grpc.insecure_channel('{}:{}'.format(url.hostname, port),
+ options=[("grpc.keepalive_time_ms", _KEEPALIVE_TIME_MS)])
elif url.scheme == 'https':
port = url.port or 443
@@ -1037,7 +1041,8 @@ class CASRemote():
credentials = grpc.ssl_channel_credentials(root_certificates=server_cert_bytes,
private_key=client_key_bytes,
certificate_chain=client_cert_bytes)
- self.channel = grpc.secure_channel('{}:{}'.format(url.hostname, port), credentials)
+ self.channel = grpc.secure_channel('{}:{}'.format(url.hostname, port), credentials,
+ options=[("grpc.keepalive_time_ms", _KEEPALIVE_TIME_MS)])
else:
raise CASError("Unsupported URL: {}".format(self.spec.url))