Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/Aspire.Hosting/Dcp/DcpExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ private async Task CreateContainersAndExecutablesAsync(CancellationToken cancell
var containersTask = CreateContainersAsync(toCreate.Where(ar => ar.DcpResource is Container), cancellationToken);
var executablesTask = CreateExecutablesAsync(toCreate.Where(ar => ar.DcpResource is Executable), cancellationToken);

await Task.WhenAll(containersTask, executablesTask).ConfigureAwait(false);
await Task.WhenAll(containersTask, executablesTask).WaitAsync(cancellationToken).ConfigureAwait(false);
}

private void AddAllocatedEndpointInfo(IEnumerable<AppResource> resources)
Expand Down Expand Up @@ -1084,10 +1084,11 @@ async Task CreateResourceExecutablesAsyncCore(IResource resource, IEnumerable<Ap
var tasks = new List<Task>();
foreach (var group in executableResources.GroupBy(e => e.ModelResource))
{
tasks.Add(CreateResourceExecutablesAsyncCore(group.Key, group, cancellationToken));
// Force this to be async so that blocking code does not stop other executables from being created.
tasks.Add(Task.Run(() => CreateResourceExecutablesAsyncCore(group.Key, group, cancellationToken), cancellationToken));
}

return Task.WhenAll(tasks);
return Task.WhenAll(tasks).WaitAsync(cancellationToken);
}
finally
{
Expand All @@ -1097,9 +1098,6 @@ async Task CreateResourceExecutablesAsyncCore(IResource resource, IEnumerable<Ap

private async Task CreateExecutableAsync(AppResource er, ILogger resourceLogger, CancellationToken cancellationToken)
{
// Force async execution
await Task.Yield();

if (er.DcpResource is not Executable exe)
{
throw new InvalidOperationException($"Expected an Executable resource, but got {er.DcpResource.Kind} instead");
Expand Down Expand Up @@ -1338,10 +1336,11 @@ async Task CreateContainerAsyncCore(AppResource cr, CancellationToken cancellati
}
}

tasks.Add(CreateContainerAsyncCore(cr, cancellationToken));
// Force this to be async so that blocking code does not stop other containers from being created.
tasks.Add(Task.Run(() => CreateContainerAsyncCore(cr, cancellationToken), cancellationToken));
}

await Task.WhenAll(tasks).ConfigureAwait(false);
await Task.WhenAll(tasks).WaitAsync(cancellationToken).ConfigureAwait(false);
}
finally
{
Expand All @@ -1351,9 +1350,6 @@ async Task CreateContainerAsyncCore(AppResource cr, CancellationToken cancellati

private async Task CreateContainerAsync(AppResource cr, ILogger resourceLogger, CancellationToken cancellationToken)
{
// Force async execution
await Task.Yield();

await _executorEvents.PublishAsync(new OnResourceStartingContext(cancellationToken, KnownResourceTypes.Container, cr.ModelResource, cr.DcpResource.Metadata.Name)).ConfigureAwait(false);

var dcpContainerResource = (Container)cr.DcpResource;
Expand Down
Loading