Browse Source

Add a timeout to the docker command (#578)

pull/579/head
David Fowler 6 years ago
committed by GitHub
parent
commit
b754925368
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/Microsoft.Tye.Core/DockerDetector.cs

7
src/Microsoft.Tye.Core/DockerDetector.cs

@ -3,12 +3,15 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Tye
{
public class DockerDetector
{
private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(10);
public static DockerDetector Instance { get; } = new DockerDetector();
private DockerDetector()
@ -25,7 +28,7 @@ namespace Microsoft.Tye
{
try
{
await ProcessUtil.RunAsync("docker", "version", throwOnError: false);
await ProcessUtil.RunAsync("docker", "version", throwOnError: false, cancellationToken: new CancellationTokenSource(Timeout).Token);
return true;
}
catch (Exception)
@ -39,7 +42,7 @@ namespace Microsoft.Tye
{
try
{
var result = await ProcessUtil.RunAsync("docker", "version", throwOnError: false);
var result = await ProcessUtil.RunAsync("docker", "version", throwOnError: false, cancellationToken: new CancellationTokenSource(Timeout).Token);
return result.ExitCode == 0;
}
catch (Exception)

Loading…
Cancel
Save