From 0987c731ec7abf2f65fd42ea5e362c14edd96bf6 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 1 May 2024 20:03:31 +0200 Subject: [PATCH] backend: configure protocol-level connection health checks This should detect a connection that is stuck for more than 2 minutes. --- internal/backend/http_transport.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/backend/http_transport.go b/internal/backend/http_transport.go index 19b20dc6a..354611e07 100644 --- a/internal/backend/http_transport.go +++ b/internal/backend/http_transport.go @@ -13,6 +13,7 @@ import ( "github.com/peterbourgon/unixtransport" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "golang.org/x/net/http2" ) // TransportOptions collects various options which can be set for an HTTP based @@ -74,7 +75,6 @@ func Transport(opts TransportOptions) (http.RoundTripper, error) { KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, - ForceAttemptHTTP2: true, MaxIdleConns: 100, MaxIdleConnsPerHost: 100, IdleConnTimeout: 90 * time.Second, @@ -83,6 +83,17 @@ func Transport(opts TransportOptions) (http.RoundTripper, error) { TLSClientConfig: &tls.Config{}, } + // ensure that http2 connections are closed if they are broken + h2, err := http2.ConfigureTransports(tr) + if err != nil { + panic(err) + } + if feature.Flag.Enabled(feature.HTTPTimeouts) { + h2.WriteByteTimeout = 120 * time.Second + h2.ReadIdleTimeout = 60 * time.Second + h2.PingTimeout = 60 * time.Second + } + unixtransport.Register(tr) if opts.InsecureTLS {