fix: SubscribeAsync throws DaprException when sidecar is unavailable#1803
Merged
Conversation
…ble and supports error handler callback Fixes #1663 - SubscribeAsync catches RpcException during initial connection and wraps in DaprException - Resets hasInitialized flag on failure to allow retry - Added SubscriptionErrorHandler delegate to DaprSubscriptionOptions for handling background task failures - HandleTaskCompletion invokes error handler when configured, preserving existing behavior when not - Updated and added unit tests for all scenarios Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/43bcaf39-8a3f-49c1-91df-f57b43a700bb Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/43bcaf39-8a3f-49c1-91df-f57b43a700bb Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
WhitWaldo
May 3, 2026 00:40
View session
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1803 +/- ##
==========================================
+ Coverage 65.50% 65.54% +0.04%
==========================================
Files 295 295
Lines 8658 8678 +20
Branches 1003 1004 +1
==========================================
+ Hits 5671 5688 +17
- Misses 2742 2745 +3
Partials 245 245
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Jun 11, 2026
This was referenced Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1663 -
SubscribeAsyncsilently fails with unobserved task exceptions when Dapr sidecar is unavailable.Changes
1. Initial connection failure now throws
DaprExceptionSubscribeAsynccatchesRpcExceptionfrom the gRPC stream setup and wraps it in aDaprExceptionwith a descriptive message including the topic and pubsub names. Callers get a catchable exception immediately instead of a silent no-op.2. Retryability
The
hasInitializedflag is reset on any failure path during initial connection, so callers can retrySubscribeAsyncafter the sidecar becomes available without needing to create a new receiver.3. Background task error handling via
SubscriptionErrorHandlerAdded
SubscriptionErrorHandlerdelegate andErrorHandlerproperty onDaprSubscriptionOptions. When background tasks (sidecar streaming, acknowledgement processing, message processing) fault after a successful subscription,HandleTaskCompletioninvokes this callback with aDaprExceptionwrapping the original error.If no handler is configured, the pre-existing behavior is preserved (exception re-thrown → unobserved task exception via default .NET behavior).
4.
RpcExceptionwrapped inDaprExceptionBoth failure paths now wrap in
DaprExceptionfor consistency with the rest of the SDK:DaprExceptionwith message referencing the topic/pubsub name, innerRpcExceptionDaprExceptionwith message referencing the active subscription, inner exception from the faulted taskTest coverage
All scenarios have dedicated unit tests validating the behavior (65 tests pass).
Breaking changes
HandleTaskCompletionis now an instance method (was static). This is aninternalmethod so no public API break.ErrorHandleris configured and a background task faults, the thrown exception type changes fromAggregateExceptiontoDaprException(wrapping the original exception).