Skip to content

Commit

Permalink
(GH-1224) support longer timeouts
Browse files Browse the repository at this point in the history
When CommandExecutionTimeoutSeconds is set to 0, do not set the
WebResponseTimeout environment variable, let it be the default.  Also
if the wait time is 0, do not set a timeout on the execute task.Wait.
  • Loading branch information
ferventcoder committed Mar 30, 2017
1 parent 9182efc commit dde8c2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ public static void set_environment_variables(ChocolateyConfiguration config)
if (config.Features.AllowEmptyChecksumsSecure) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksumsSecure, "true");
if (config.Features.ScriptsCheckLastExitCode) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyCheckLastExitCode, "true");
Environment.SetEnvironmentVariable("chocolateyRequestTimeout", config.WebRequestTimeoutSeconds.to_string() + "000");
Environment.SetEnvironmentVariable("chocolateyResponseTimeout", config.CommandExecutionTimeoutSeconds.to_string() + "000");


if (config.CommandExecutionTimeoutSeconds != 0)
{
Environment.SetEnvironmentVariable("chocolateyResponseTimeout", config.CommandExecutionTimeoutSeconds.to_string() + "000");
}

if (!string.IsNullOrWhiteSpace(config.Proxy.Location))
{
var proxyCreds = string.Empty;
Expand Down
11 changes: 10 additions & 1 deletion src/chocolatey/infrastructure/commands/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ public bool command(Action action)
var cancelToken = new CancellationTokenSource();
cancelToken.Token.ThrowIfCancellationRequested();
var task = Task.Factory.StartNew(action, cancelToken.Token);
task.Wait(_timespan);
if (_timespan.TotalSeconds < 1d)
{
// 0 means infinite
task.Wait();
}
else
{
task.Wait(_timespan);
}

completed = task.IsCompleted;

if (!completed)
Expand Down

0 comments on commit dde8c2b

Please sign in to comment.