Skip to content

Fix SubscribeAsync silently failing when Dapr sidecar is unavailable#1744

Open
GeorgeTsiokos wants to merge 1 commit intodapr:masterfrom
GeorgeTsiokos:fix/subscribe-async-silent-failure-1663
Open

Fix SubscribeAsync silently failing when Dapr sidecar is unavailable#1744
GeorgeTsiokos wants to merge 1 commit intodapr:masterfrom
GeorgeTsiokos:fix/subscribe-async-silent-failure-1663

Conversation

@GeorgeTsiokos
Copy link

Summary

Fixes #1663

  • Throw on initial connection failure: SubscribeAsync now catches RpcException from the gRPC stream setup and throws a DaprException with context (topic name, pubsub name), allowing callers to detect and handle sidecar unavailability
  • Error callback for runtime errors: Added SubscriptionErrorHandler delegate and ErrorHandler property on DaprSubscriptionOptions so callers can receive DaprException-wrapped errors from background tasks instead of having them become UnobservedTaskExceptions
  • Retryable after failure: Resets hasInitialized flag on both initial connection failures and mid-stream background task failures, so callers can retry SubscribeAsync
  • Safe error handler invocation: Guards ErrorHandler?.Invoke() with try/catch to prevent a faulty handler from recreating unobserved exceptions
  • ContinueWith uses CancellationToken.None: Ensures error-handling continuations always execute even after cancellation

Test plan

  • HandleTaskCompletion invokes ErrorHandler with DaprException wrapping the original exception
  • HandleTaskCompletion does not throw when no ErrorHandler is set
  • HandleTaskCompletion does not throw when ErrorHandler itself throws
  • HandleTaskCompletion does not invoke ErrorHandler for successful tasks
  • SubscribeAsync throws DaprException wrapping RpcException when sidecar unavailable
  • SubscribeAsync allows retry after RpcException failure (hasInitialized reset)
  • SubscribeAsync resets hasInitialized for non-RPC exceptions (e.g. ObjectDisposedException)
  • All 22 tests pass on net9.0 and net10.0

🤖 Generated with Claude Code

@GeorgeTsiokos GeorgeTsiokos requested review from a team as code owners March 13, 2026 10:19
…apr#1663)

- Throw DaprException wrapping RpcException on initial connection failure
- Add SubscriptionErrorHandler callback for runtime errors in background tasks
- Reset hasInitialized on any failure (initial or mid-stream) to allow retry
- Guard ErrorHandler invocation with try/catch to prevent unobserved exceptions
- Use CancellationToken.None for ContinueWith to ensure error handlers fire
- Include topic/pubsub names in error messages for multi-subscription debugging

Resolves dapr#1663

Signed-off-by: George Tsiokos <george@tsiokos.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GeorgeTsiokos GeorgeTsiokos force-pushed the fix/subscribe-async-silent-failure-1663 branch from 74b1b32 to 9ce96c6 Compare March 13, 2026 10:22
@WhitWaldo
Copy link
Contributor

Do note that I just merged a PR to support xUnit v3 so your unit/integration tests may need a refresh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Messaging] SubscribeAsync silently fails with unobserved task exceptions when Dapr sidecar is unavailable

2 participants