From 43d173b04270522d6fb477ea9b192c9db1b3f7ed Mon Sep 17 00:00:00 2001 From: phcreery Date: Wed, 15 Sep 2021 19:27:47 -0500 Subject: [PATCH 1/2] rclone: add timeout option and documentation --- changelog/unreleased/pull-3514 | 7 +++++++ doc/030_preparing_a_new_repo.rst | 3 ++- internal/backend/rclone/backend.go | 2 +- internal/backend/rclone/config.go | 5 ++++- internal/backend/rclone/config_test.go | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/pull-3514 diff --git a/changelog/unreleased/pull-3514 b/changelog/unreleased/pull-3514 new file mode 100644 index 000000000..57ecb52d0 --- /dev/null +++ b/changelog/unreleased/pull-3514 @@ -0,0 +1,7 @@ +Enhancement: Support timeout configurable for rclone backend + +A slow rclone backend could cause restic to time out while waiting for the repository to open. +Restic now offers an `-o rclone.timeout` option to make this timeout configurable. + +https://github.com/restic/restic/issues/3511 +https://github.com/restic/restic/pull/3514 \ No newline at end of file diff --git a/doc/030_preparing_a_new_repo.rst b/doc/030_preparing_a_new_repo.rst index 71337e551..19fb5d17b 100644 --- a/doc/030_preparing_a_new_repo.rst +++ b/doc/030_preparing_a_new_repo.rst @@ -607,10 +607,11 @@ configuring a bandwidth limit for rclone can be achieved by setting the For debugging rclone, you can set the environment variable ``RCLONE_VERBOSE=2``. -The rclone backend has two additional options: +The rclone backend has three additional options: * ``-o rclone.program`` specifies the path to rclone, the default value is just ``rclone`` * ``-o rclone.args`` allows setting the arguments passed to rclone, by default this is ``serve restic --stdio --b2-hard-delete`` +* ``-o rclone.timeout`` specifies timeout for waiting on repository opening, the default value is ``1m`` The reason for the ``--b2-hard-delete`` parameters can be found in the corresponding GitHub `issue #1657`_. diff --git a/internal/backend/rclone/backend.go b/internal/backend/rclone/backend.go index 8e0c7fe4d..52cd87f8c 100644 --- a/internal/backend/rclone/backend.go +++ b/internal/backend/rclone/backend.go @@ -222,7 +222,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) { // send an HTTP request to the base URL, see if the server is there client := &http.Client{ Transport: debug.RoundTripper(tr), - Timeout: 60 * time.Second, + Timeout: cfg.Timeout * 60 * time.Second, } // request a random file which does not exist. we just want to test when diff --git a/internal/backend/rclone/config.go b/internal/backend/rclone/config.go index 697a71a6d..7b2b23efd 100644 --- a/internal/backend/rclone/config.go +++ b/internal/backend/rclone/config.go @@ -2,6 +2,7 @@ package rclone import ( "strings" + "time" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/options" @@ -12,13 +13,15 @@ type Config struct { Program string `option:"program" help:"path to rclone (default: rclone)"` Args string `option:"args" help:"arguments for running rclone (default: serve restic --stdio --b2-hard-delete)"` Remote string - Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` + Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` + Timeout time.Duration `option:"timeout" help:"set a timeout limit to wait for rclone to establish a connection (default: 1m)"` } var defaultConfig = Config{ Program: "rclone", Args: "serve restic --stdio --b2-hard-delete", Connections: 5, + Timeout: "1m", } func init() { diff --git a/internal/backend/rclone/config_test.go b/internal/backend/rclone/config_test.go index d9dcdc251..923555136 100644 --- a/internal/backend/rclone/config_test.go +++ b/internal/backend/rclone/config_test.go @@ -17,6 +17,7 @@ func TestParseConfig(t *testing.T) { Program: defaultConfig.Program, Args: defaultConfig.Args, Connections: defaultConfig.Connections, + Timeout: defaultConfig.Timeout, }, }, } From b0e64deb2797d0811cc7b8506ea1d9f774fb9cdd Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 7 Nov 2021 17:47:18 +0100 Subject: [PATCH 2/2] rclone: Fix timeout calculation --- internal/backend/rclone/backend.go | 2 +- internal/backend/rclone/config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/backend/rclone/backend.go b/internal/backend/rclone/backend.go index 52cd87f8c..8c1305f7f 100644 --- a/internal/backend/rclone/backend.go +++ b/internal/backend/rclone/backend.go @@ -222,7 +222,7 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) { // send an HTTP request to the base URL, see if the server is there client := &http.Client{ Transport: debug.RoundTripper(tr), - Timeout: cfg.Timeout * 60 * time.Second, + Timeout: cfg.Timeout, } // request a random file which does not exist. we just want to test when diff --git a/internal/backend/rclone/config.go b/internal/backend/rclone/config.go index 7b2b23efd..f8dc0d84d 100644 --- a/internal/backend/rclone/config.go +++ b/internal/backend/rclone/config.go @@ -21,7 +21,7 @@ var defaultConfig = Config{ Program: "rclone", Args: "serve restic --stdio --b2-hard-delete", Connections: 5, - Timeout: "1m", + Timeout: time.Minute, } func init() {