fix: handle graceful cancellation in CloudEventsMiddleware to prevent 499 errors#1713
Merged
WhitWaldo merged 2 commits intodapr:masterfrom Feb 23, 2026
Merged
Conversation
951b0f3 to
a70c99e
Compare
Contributor
|
Thank you for your contribution here! No notes - this looks great. That said, I cannot merge this until you've signed your commits. Once you do that, I'd be more than happy to merge as-is. Again, thank you! |
… 499 errors Propagate CancellationToken to JsonSerializer and handle OperationCanceledException gracefully when the response has already started. This prevents erroneous 499 Client Closed Connection errors in PubSub consumers under high load. Fixes dapr#1237 Signed-off-by: ali-Hamza817 <alihamzaminhas.21@gmail.com>
- Fix test ordering: move app.Run() before app.Build() to match the pattern of all other tests in the file - Use IHttpResponseFeature to properly simulate HasStarted=true since DefaultHttpContext doesn't set it from WriteAsync - Add new test: PropagatesCancellation_WhenResponseHasNotStarted to verify exceptions are NOT swallowed when the response has not started (correct ASP.NET Core behavior) Signed-off-by: ali-Hamza817 <alihamzaminhas.21@gmail.com>
595c9b4 to
75cb668
Compare
This was referenced Mar 2, 2026
This was referenced Mar 9, 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.
Description
This PR addresses the "499 Client Closed Connection" error in Pub/Sub consumers by properly propagating the CancellationToken from the HttpContext to the JsonSerializer. It also implements a graceful catch for OperationCanceledException that swallows the error ONLY if the response has already started, preventing erroneous telemetry failures during high-load race conditions.
Issue reference
Fixes #1237
Checklist