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 {