microsoft/aspire · warning · OperationCanceledException
Resource ' ' failed to wait for dependencies before the…
Error message
Resource '{resource.Name}' failed to wait for dependencies before the operation was cancelled. What it means
Wraps an OperationCanceledException raised while waiting for dependency resources, producing a clearer cancellation message via BuildCancellationErrorMessage and rethrowing OperationCanceledException. It signals that the AppHost/resource start was cancelled before dependencies finished waiting.
Solutions
- Check whether cancellation was user-initiated (Ctrl+C) — if so, no fix needed; this is expected shutdown behavior.
- If cancellation is unintended, extend timeouts in test harnesses / hosting environments and avoid disposing the AppHost prematurely.
- Diagnose why the dependency was slow: slow image pulls or health checks can make startup outlast the operator's patience.
- Catch OperationCanceledException around AppHost startup/run in host processes to shut down gracefully.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
await app.StartAsync();
}
catch (OperationCanceledException ex) when (ex.Message.Contains("failed to wait for dependencies"))
{
logger.LogWarning(ex, "AppHost startup was cancelled while waiting for dependencies.");
} Prevention
- Avoid stopping the AppHost while dependencies are still starting.
- Use adequate timeouts in test harnesses that start AppHosts.
- Pre-pull large container images to shorten dependency waits.
- Treat this as expected on Ctrl+C; only investigate if cancellation is unintended.
When it happens
Trigger: Ctrl+C / AppHost shutdown, debugger stop, or an already-cancelled CancellationToken reaching WaitForDependenciesAsync while one or more Task dependencies are still pending.
Common situations: User cancels the AppHost while a dependency is still starting; Ctrl+C during `aspire run`; test harnesses with short timeouts canceling orchestration; host shutdown triggered by another resource failing fast.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
Related errors
- {cancellationMessage}
- A circular lifetime reference was detected for resource
- A global MCP approval policy cannot be combined with custom…
- A security rule named
- adminPassword
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/4e6d171379716d80.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:588
finally
{
pendingDependencyLock.Release();
}
if (clearRemainingDependencies)
{
await ClearWaitingForDependenciesAsync(resource).ConfigureAwait(false);
}
}
catch (OperationCanceledException ex)
{
activity.SetError(ex);
var errorMessage = BuildCancellationErrorMessage(
$"Resource '{resource.Name}' failed to wait for dependencies before the operation was cancelled.",
resource.Name);
throw new OperationCanceledException(errorMessage, ex, ex.CancellationToken);
}
catch (Exception ex)
{
activity.SetError(ex);
throw;
}
}
private Task PublishWaitingForDependenciesAsync(IResource resource, IEnumerable<string> dependencyNames)
{
var waitingFor = dependencyNames
.Where(static dependencyName => !string.IsNullOrWhiteSpace(dependencyName))
.Distinct(StringComparers.ResourceName)
.ToArray();
// Explicit-start resources should not auto-transition to Waiting even if they have dependencies
// (they should be considered Waiting only after an attempt is made to start them).
// Resources with no instances managed by Aspire do not "start" from Aspire's perspective, View on GitHub (pinned to 25830f84bd)