From 9f3f230245236cf65b5062e1c10b2667bc603f43 Mon Sep 17 00:00:00 2001 From: Julien Kauffmann Date: Thu, 17 Aug 2017 13:45:10 -0400 Subject: [PATCH 1/2] Made command timeouts configurable --- README.md | 9 +++++++++ internal/gps/cmd.go | 25 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 91b829f1dd..9a823b506a 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,15 @@ You might, for example, include a constraint in your manifest that specifies `ve * `0.2.3` becomes the range `>=0.2.3, <0.3.0` * `0.0.3` becomes the range `>=0.0.3, <0.1.0` +## Timeouts + +`dep ensure` can sometime fail on very slow system due to underlying operations taking too long to perform. This is especially true on Windows due to filesystem issues. + +If the built-in timeouts are not suitable to your environment, you can override those by setting specific environment variables: + +* `DEP_EXPENSIVE_CMD_TIMEOUT`: Set the maximum number of seconds expensive operations can take. The default is 2 minutes (120 seconds). +* `DEP_DEFAULT_CMD_TIMEOUT`: Set the maximum number of seconds common operations can take. The default is 10 seconds. + ## Feedback Feedback is greatly appreciated. diff --git a/internal/gps/cmd.go b/internal/gps/cmd.go index 4e0b2d3a83..e2f37adf7a 100644 --- a/internal/gps/cmd.go +++ b/internal/gps/cmd.go @@ -8,7 +8,9 @@ import ( "bytes" "context" "fmt" + "os" "os/exec" + "strconv" "sync" "sync/atomic" "time" @@ -196,12 +198,31 @@ func runFromRepoDir(ctx context.Context, repo vcs.Repo, timeout time.Duration, c return c.combinedOutput(ctx) } +func getenvDuration(key string, def time.Duration) time.Duration { + seconds, err := strconv.Atoi(os.Getenv(key)) + + if err != nil { + return def + } + + return time.Duration(seconds) * time.Second +} + const ( + // envExpensiveCmdTimeout is the environment variable to read for the + // expensiveCmdTimeout default, in seconds. + envExpensiveCmdTimeout = "DEP_EXPENSIVE_CMD_TIMEOUT" + // envDefaultCmdTimeout is the environment variable to read for the + // envDefaultCmdTimeout default, in seconds. + envDefaultCmdTimeout = "DEP_DEFAULT_CMD_TIMEOUT" +) + +var ( // expensiveCmdTimeout is meant to be used in a command that is expensive // in terms of computation and we know it will take long or one that uses // the network, such as clones, updates, .... - expensiveCmdTimeout = 2 * time.Minute + expensiveCmdTimeout = getenvDuration(envExpensiveCmdTimeout, 2*time.Minute) // defaultCmdTimeout is just an umbrella value for all other commands that // should not take much. - defaultCmdTimeout = 10 * time.Second + defaultCmdTimeout = getenvDuration(envDefaultCmdTimeout, 10*time.Second) ) From 12a8bc2b0ec78819c234a6d56d719499ee0dcff4 Mon Sep 17 00:00:00 2001 From: Julien Kauffmann Date: Wed, 23 Aug 2017 22:45:52 -0400 Subject: [PATCH 2/2] Got rid of the Windows mention in the timeouts section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a823b506a..805b26e0c8 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ You might, for example, include a constraint in your manifest that specifies `ve ## Timeouts -`dep ensure` can sometime fail on very slow system due to underlying operations taking too long to perform. This is especially true on Windows due to filesystem issues. +`dep ensure` can sometime fail on very slow system due to underlying operations taking too long to perform. If the built-in timeouts are not suitable to your environment, you can override those by setting specific environment variables: