From: Gregor Jasny Date: Fri, 1 Oct 2021 06:54:38 +0000 (+0200) Subject: feat(http-storage): Make HTTP keep-alive configurable X-Git-Tag: v4.5~23^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6231c545756be10edc8051a25fbf587ccaceabb;p=thirdparty%2Fccache.git feat(http-storage): Make HTTP keep-alive configurable --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index e29d0a201..433f38559 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -1080,6 +1080,14 @@ Examples: Optional attributes: * *connect-timeout*: Timeout (in ms) for network connection. The default is 100. +* *keep-alive*: If *true*, keep the HTTP connection to the storage server open +to avoid reconnects. The default is *false*. ++ +NOTE: Connection keep-alive is disabled by default because with the current +HTTP implementation uploads to the remote end might fail in case the server +closes the connection due to a keep-alive timeout. If the general case with +short compilation times should be accelerated or the server is configured with +a long-enough timeout, then connection keep-alive could be enabled. * *layout*: How to map key names to the path part of the URL. Available values: + -- diff --git a/src/storage/secondary/HttpStorage.cpp b/src/storage/secondary/HttpStorage.cpp index bf7e5802b..4d5ab2998 100644 --- a/src/storage/secondary/HttpStorage.cpp +++ b/src/storage/secondary/HttpStorage.cpp @@ -110,6 +110,7 @@ HttpStorageBackend::HttpStorageBackend(const Params& params) m_http_client.set_default_headers({ {"User-Agent", FMT("{}/{}", CCACHE_NAME, CCACHE_VERSION)}, }); + m_http_client.set_keep_alive(false); auto connect_timeout = k_default_connect_timeout; auto operation_timeout = k_default_operation_timeout; @@ -117,6 +118,8 @@ HttpStorageBackend::HttpStorageBackend(const Params& params) for (const auto& attr : params.attributes) { if (attr.key == "connect-timeout") { connect_timeout = parse_timeout_attribute(attr.value); + } else if (attr.key == "keep-alive") { + m_http_client.set_keep_alive(attr.value == "true"); } else if (attr.key == "layout") { if (attr.value == "bazel") { m_layout = Layout::bazel;