Skip to content

fix: SubscribeAsync throws DaprException when sidecar is unavailable#1803

Merged
WhitWaldo merged 4 commits into
masterfrom
copilot/fix-issue-1663
May 3, 2026
Merged

fix: SubscribeAsync throws DaprException when sidecar is unavailable#1803
WhitWaldo merged 4 commits into
masterfrom
copilot/fix-issue-1663

Conversation

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1663 - SubscribeAsync silently fails with unobserved task exceptions when Dapr sidecar is unavailable.

Changes

1. Initial connection failure now throws DaprException

SubscribeAsync catches RpcException from the gRPC stream setup and wraps it in a DaprException with a descriptive message including the topic and pubsub names. Callers get a catchable exception immediately instead of a silent no-op.

2. Retryability

The hasInitialized flag is reset on any failure path during initial connection, so callers can retry SubscribeAsync after the sidecar becomes available without needing to create a new receiver.

3. Background task error handling via SubscriptionErrorHandler

Added SubscriptionErrorHandler delegate and ErrorHandler property on DaprSubscriptionOptions. When background tasks (sidecar streaming, acknowledgement processing, message processing) fault after a successful subscription, HandleTaskCompletion invokes this callback with a DaprException wrapping 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. RpcException wrapped in DaprException

Both failure paths now wrap in DaprException for consistency with the rest of the SDK:

  • Initial connection failure: DaprException with message referencing the topic/pubsub name, inner RpcException
  • Background task failure: DaprException with message referencing the active subscription, inner exception from the faulted task

Test coverage

All scenarios have dedicated unit tests validating the behavior (65 tests pass).

Breaking changes

  • HandleTaskCompletion is now an instance method (was static). This is an internal method so no public API break.
  • When no ErrorHandler is configured and a background task faults, the thrown exception type changes from AggregateException to DaprException (wrapping the original exception).

Copilot AI and others added 2 commits May 3, 2026 00:35
…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>
@codecov

codecov Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.54%. Comparing base (843b73a) to head (5e41a48).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...aging/PublishSubscribe/PublishSubscribeReceiver.cs 88.88% 3 Missing ⚠️
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              
Flag Coverage Δ
net10.0 65.53% <89.28%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@WhitWaldo WhitWaldo marked this pull request as ready for review May 3, 2026 09:46
@WhitWaldo WhitWaldo requested review from a team as code owners May 3, 2026 09:46
@WhitWaldo WhitWaldo merged commit 0a41199 into master May 3, 2026
310 of 313 checks passed
@nelson-parente nelson-parente added this to the v1.18 milestone May 20, 2026
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

3 participants