microsoft/aspire · warning · OperationCanceledException

{cancellationMessage}

Error message

{cancellationMessage}

What it means

WaitForResourceEventAsync wraps OperationCanceledException from watching resource notifications and rethrows it with a descriptive cancellationMessage explaining which wait was cancelled (e.g. 'failed to become healthy before the operation was cancelled'). This is the inner-exception variant, preserving the original exception and its token.

Solutions

  1. Increase request.TimeoutSeconds if the resource legitimately needs more time.
  2. Check why the resource never reached the expected state (dashboard logs/state).
  3. Inspect ex.CancellationToken / inner exception to determine whether the caller or the timeout cancelled.
  4. Retry the wait once startup contention (slow image pull, cold start) has passed.

Example fix

// before
var resp = await rpc.WaitForResourceAsync(new WaitForResourceRequest { ResourceName = "api", Status = "healthy", TimeoutSeconds = 10 });
// after
var resp = await rpc.WaitForResourceAsync(new WaitForResourceRequest { ResourceName = "api", Status = "healthy", TimeoutSeconds = 120 });
Defensive patterns

Strategy: try-catch

Try / catch

try { await rpc.WaitForResourceAsync(request); }
catch (OperationCanceledException ex) when (timeoutCts.IsCancellationRequested) { logger.LogWarning(ex, "Wait cancelled by timeout; increase TimeoutSeconds or fix slow startup."); }

Prevention

When it happens

Trigger: WaitForResourceAsync / WaitForHealthyAsync waits cancelled via the caller's CancellationToken or the linked timeout CTS while streaming ResourceNotificationService.WatchAsync — the wait never observed a matching resource event before cancellation.

Common situations: Caller-side cancellation (Ctrl+C, RPC client disconnect); the per-request timeout firing; resource taking longer than the wait window to publish a matching event.

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


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/f9e48176e80c3e1d. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs:767

        ResourceNotificationService notificationService,
        WaitResourceTarget target,
        Func<ResourceEvent, bool> predicate,
        string cancellationMessage,
        CancellationToken cancellationToken)
    {
        try
        {
            await foreach (var resourceEvent in notificationService.WatchAsync(cancellationToken).ConfigureAwait(false))
            {
                if (target.Matches(resourceEvent) && predicate(resourceEvent))
                {
                    return resourceEvent;
                }
            }
        }
        catch (OperationCanceledException ex)
        {
            throw new OperationCanceledException(cancellationMessage, ex, ex.CancellationToken);
        }

        throw new OperationCanceledException(cancellationMessage);
    }

    private WaitTargetResolutionResult ResolveWaitTarget(ResourceNotificationService notificationService, string requestedResourceName)
    {
        var appModel = serviceProvider.GetRequiredService<DistributedApplicationModel>();
        if (notificationService.TryGetCurrentState(requestedResourceName, out var resourceEvent))
        {
            return WaitTargetResolutionResult.Success(new WaitResourceTarget(
                ResolveDisplayName(appModel, requestedResourceName, resourceEvent.ResourceId),
                resourceEvent.ResourceId,
                null));
        }

        // During startup the resource may not have published its first snapshot yet, so fall back to
        // the app model to resolve the requested logical name or resolved resource id.

View on GitHub (pinned to 25830f84bd)