From 7e6008036f05d82e14d2021df7239950be97963c Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Wed, 25 Oct 2023 11:35:58 -0700 Subject: [PATCH] Use cancellation token and increase timeout for docker inspect fetching env vars Resolves #491 --- src/Aspire.Hosting/Dashboard/ViewModelCache.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Aspire.Hosting/Dashboard/ViewModelCache.cs b/src/Aspire.Hosting/Dashboard/ViewModelCache.cs index 349b8d8a23..73def030f3 100644 --- a/src/Aspire.Hosting/Dashboard/ViewModelCache.cs +++ b/src/Aspire.Hosting/Dashboard/ViewModelCache.cs @@ -293,7 +293,7 @@ when _filterResource(customResource) && ProcessChange(_resourceMap, watchEventTy { // Container is ready to be inspected // This task when returns will generate a notification in channel - _ = Task.Run(() => ComputeEnvironmentVariablesFromDocker(container)); + _ = Task.Run(() => ComputeEnvironmentVariablesFromDocker(container, _cancellationToken)); _resourcesWithTaskLaunched.Add(name); } // For containers we always send list of env vars which we may have computed earlier from docker command @@ -350,7 +350,7 @@ public ValueTask DisposeAsync() return ValueTask.CompletedTask; } - private async Task ComputeEnvironmentVariablesFromDocker(Container container) + private async Task ComputeEnvironmentVariablesFromDocker(Container container, CancellationToken cancellationToken) { IAsyncDisposable? processDisposable = null; try @@ -367,7 +367,7 @@ private async Task ComputeEnvironmentVariablesFromDocker(Container container) (task, processDisposable) = ProcessUtil.Run(spec); - var exitCode = (await task.WaitAsync(TimeSpan.FromSeconds(5)).ConfigureAwait(false)).ExitCode; + var exitCode = (await task.WaitAsync(TimeSpan.FromSeconds(30), cancellationToken).ConfigureAwait(false)).ExitCode; if (exitCode == 0) { var jsonArray = JsonNode.Parse(outputStringBuilder.ToString())?.AsArray();