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/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
|
||||
|
|
|
@ -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."},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue