Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #763 from jeschu1/timeout2
Browse files Browse the repository at this point in the history
cli: add GCM_HTTP_TIMEOUT and httpTimeout support
  • Loading branch information
jeschu1 authored Sep 21, 2018
2 parents afedbe1 + c25ad07 commit b76af7e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ git config --global credential.visualstudio.com.preserve true

See [GCM_PRESERVE](Environment.md#gcm_preserve)

### httpTimeout

Sets the maximum time, in milliseconds, for a network request to wait before timing out.
This allows changing the default for slow connections.

Supports an integer value. Defaults to 90,000 miliseconds.

```shell
git config --global credential.visualstudio.com.httpTimeout 100000
```

See [GCM_HTTP_TIMEOUT](Environment.md#gcm_http_timeout)

### tokenDuration

Sets a duration, in hours, limit for the validity of Personal Access Tokens requested from Azure DevOps.
Expand Down
9 changes: 9 additions & 0 deletions Docs/Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ Supports `true` or `false`. Defaults to `false`.

See [credential.preserve](Configuration.md#preserve).

### GCM_HTTP_TIMEOUT

Sets the maximum time, in milliseconds, for a network request to wait before timing out.
This allows changing the default for slow connections.

Supports an integer value. Defaults to 90,000 miliseconds.

See [credential.httpTimeout](Configuration.md#httpTimeout).

### GCM_TOKEN_DURATION

Sets a duration, in hours, limit for the validity of Personal Access Tokens requested from Azure DevOps.
Expand Down
12 changes: 7 additions & 5 deletions Microsoft.Alm.Authentication/Src/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ public static class Global
/// </summary>
public const int MaxAutomaticRedirections = 16;

/// <summary>
/// The maximum wait time for a network request before timing out
/// </summary>
public const int RequestTimeout = 90 * 1000; // 90 second limit

private static int _requestTimeout = 90 * 1000; // 90 second default limit.
private static readonly object _syncpoint = new object();
private static string _useragent = BuildDefaultUserAgent(RuntimeContext.Default);

Expand Down Expand Up @@ -67,6 +63,12 @@ public static string UserAgent

}

public static int RequestTimeout
{
get { lock (_syncpoint) return _requestTimeout; }
set { lock (_syncpoint) _requestTimeout = value; }
}

private static string BuildDefaultUserAgent(RuntimeContext context)
{
if (context is null)
Expand Down
11 changes: 11 additions & 0 deletions Shared/Cli/Functions/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,17 @@ public static async Task LoadOperationArguments(Program program, OperationArgume
operationArguments.UrlOverride = value;
}
}

// Look for timeout override.
if (program.TryReadString(operationArguments, KeyType.HttpTimeout, out value))
{
program.Trace.WriteLine($"{program.KeyTypeName(KeyType.HttpTimeout)} = '{value}'.");

if (int.TryParse(value, out int milliseconds))
{
Global.RequestTimeout = milliseconds;
}
}
}

public static void LogEvent(Program program, string message, EventLogEntryType eventType)
Expand Down
3 changes: 3 additions & 0 deletions Shared/Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum KeyType
HttpPath,
HttpProxy,
HttpsProxy,
HttpTimeout,
HttpUserAgent,
Interactive,
ModalPrompt,
Expand Down Expand Up @@ -129,6 +130,7 @@ partial class Program
{ KeyType.PreserveCredentials, "preserve" },
{ KeyType.TokenDuration, "tokenDuration" },
{ KeyType.HttpPath, "useHttpPath" },
{ KeyType.HttpTimeout, "httpTimeout" },
{ KeyType.Username, "username" },
{ KeyType.Validate, "validate" },
{ KeyType.VstsScope,"vstsScope" },
Expand All @@ -142,6 +144,7 @@ partial class Program
{ KeyType.DevOpsScope, "GCM_DEVOPS_SCOPE" },
{ KeyType.HttpProxy, "HTTP_PROXY" },
{ KeyType.HttpsProxy, "HTTPS_PROXY" },
{ KeyType.HttpTimeout, "GCM_HTTP_TIMEOUT" },
{ KeyType.HttpUserAgent, "GCM_HTTP_USER_AGENT" },
{ KeyType.Interactive, "GCM_INTERACTIVE" },
{ KeyType.ModalPrompt, "GCM_MODAL_PROMPT" },
Expand Down

0 comments on commit b76af7e

Please sign in to comment.