{"record":{"id":"4e6d171379716d80","repo":"microsoft/aspire","slug":"resource-resource-name-failed-to-wait-for-dependencies","errorCode":null,"errorMessage":"Resource '{resource.Name}' failed to wait for dependencies before the operation was cancelled.","messagePattern":"Resource '(.+?)' failed to wait for dependencies before the operation was cancelled\\.","errorType":"exception","errorClass":"OperationCanceledException","httpStatus":null,"severity":"warning","filePath":"src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs","lineNumber":588,"sourceCode":"            finally\n            {\n                pendingDependencyLock.Release();\n            }\n\n            if (clearRemainingDependencies)\n            {\n                await ClearWaitingForDependenciesAsync(resource).ConfigureAwait(false);\n            }\n        }\n        catch (OperationCanceledException ex)\n        {\n            activity.SetError(ex);\n\n            var errorMessage = BuildCancellationErrorMessage(\n                $\"Resource '{resource.Name}' failed to wait for dependencies before the operation was cancelled.\",\n                resource.Name);\n\n            throw new OperationCanceledException(errorMessage, ex, ex.CancellationToken);\n        }\n        catch (Exception ex)\n        {\n            activity.SetError(ex);\n            throw;\n        }\n    }\n\n    private Task PublishWaitingForDependenciesAsync(IResource resource, IEnumerable<string> dependencyNames)\n    {\n        var waitingFor = dependencyNames\n            .Where(static dependencyName => !string.IsNullOrWhiteSpace(dependencyName))\n            .Distinct(StringComparers.ResourceName)\n            .ToArray();\n\n        // Explicit-start resources should not auto-transition to Waiting even if they have dependencies\n        // (they should be considered Waiting only after an attempt is made to start them).\n        // Resources with no instances managed by Aspire do not \"start\" from Aspire's perspective, ","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs#L570-L606","documentation":"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.","triggerScenarios":"Ctrl+C / AppHost shutdown, debugger stop, or an already-cancelled CancellationToken reaching WaitForDependenciesAsync while one or more Task dependencies are still pending.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await app.StartAsync();\n}\ncatch (OperationCanceledException ex) when (ex.Message.Contains(\"failed to wait for dependencies\"))\n{\n    logger.LogWarning(ex, \"AppHost startup was cancelled while waiting for dependencies.\");\n}","preventionTips":["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."],"tags":["aspire","cancellation","dependency-wait","shutdown"],"backgroundTag":"request-timeout","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}