From 1b9e89b478e2015201040b40bcd319dd017e0c8f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 22 Apr 2024 21:41:53 +0200 Subject: [PATCH] guard http timeouts with a feature flag --- internal/backend/http_transport.go | 17 +++++++++++------ internal/feature/registry.go | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/backend/http_transport.go b/internal/backend/http_transport.go index 593938a20..2b9efe000 100644 --- a/internal/backend/http_transport.go +++ b/internal/backend/http_transport.go @@ -14,6 +14,7 @@ import ( "github.com/peterbourgon/unixtransport" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/feature" ) // TransportOptions collects various options which can be set for an HTTP based @@ -72,13 +73,17 @@ func Transport(opts TransportOptions) (http.RoundTripper, error) { KeepAlive: 30 * time.Second, DualStack: true, }).DialContext - // inject timeoutConn to enforce progress - dialTimeout := func(ctx context.Context, network, addr string) (net.Conn, error) { - conn, err := dial(ctx, network, addr) - if err != nil { - return conn, err + dialTimeout := dial + + if feature.Flag.Enabled(feature.HTTPTimeouts) { + // inject timeoutConn to enforce progress + dialTimeout = func(ctx context.Context, network, addr string) (net.Conn, error) { + conn, err := dial(ctx, network, addr) + if err != nil { + return conn, err + } + return newTimeoutConn(conn, 5*time.Minute) } - return newTimeoutConn(conn, 5*time.Minute) } // copied from net/http diff --git a/internal/feature/registry.go b/internal/feature/registry.go index 2d2e45edf..1b2c8207d 100644 --- a/internal/feature/registry.go +++ b/internal/feature/registry.go @@ -8,6 +8,7 @@ const ( DeprecateLegacyIndex FlagName = "deprecate-legacy-index" DeprecateS3LegacyLayout FlagName = "deprecate-s3-legacy-layout" DeviceIDForHardlinks FlagName = "device-id-for-hardlinks" + HTTPTimeouts FlagName = "http-timeouts" ) func init() { @@ -15,5 +16,6 @@ func init() { DeprecateLegacyIndex: {Type: Beta, Description: "disable support for index format used by restic 0.1.0. Use `restic repair index` to update the index if necessary."}, DeprecateS3LegacyLayout: {Type: Beta, Description: "disable support for S3 legacy layout used up to restic 0.7.0. Use `RESTIC_FEATURES=deprecate-s3-legacy-layout=false restic migrate s3_layout` to migrate your S3 repository if necessary."}, DeviceIDForHardlinks: {Type: Alpha, Description: "store deviceID only for hardlinks to reduce metadata changes for example when using btrfs subvolumes. Will be removed in a future restic version after repository format 3 is available"}, + HTTPTimeouts: {Type: Beta, Description: "improve handling of stuck HTTP connections using timeouts."}, }) }