mirror of https://github.com/restic/restic.git
guard http timeouts with a feature flag
This commit is contained in:
parent
a95608522b
commit
1b9e89b478
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/peterbourgon/unixtransport"
|
"github.com/peterbourgon/unixtransport"
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
|
"github.com/restic/restic/internal/feature"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TransportOptions collects various options which can be set for an HTTP based
|
// 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,
|
KeepAlive: 30 * time.Second,
|
||||||
DualStack: true,
|
DualStack: true,
|
||||||
}).DialContext
|
}).DialContext
|
||||||
// inject timeoutConn to enforce progress
|
dialTimeout := dial
|
||||||
dialTimeout := func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
||||||
conn, err := dial(ctx, network, addr)
|
if feature.Flag.Enabled(feature.HTTPTimeouts) {
|
||||||
if err != nil {
|
// inject timeoutConn to enforce progress
|
||||||
return conn, err
|
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
|
// copied from net/http
|
||||||
|
|
|
@ -8,6 +8,7 @@ const (
|
||||||
DeprecateLegacyIndex FlagName = "deprecate-legacy-index"
|
DeprecateLegacyIndex FlagName = "deprecate-legacy-index"
|
||||||
DeprecateS3LegacyLayout FlagName = "deprecate-s3-legacy-layout"
|
DeprecateS3LegacyLayout FlagName = "deprecate-s3-legacy-layout"
|
||||||
DeviceIDForHardlinks FlagName = "device-id-for-hardlinks"
|
DeviceIDForHardlinks FlagName = "device-id-for-hardlinks"
|
||||||
|
HTTPTimeouts FlagName = "http-timeouts"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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."},
|
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."},
|
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"},
|
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."},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue