Fix unobserved task exceptions when pending messages overflow - #2272
Open
jogibear9988 wants to merge 1 commit into
Open
jogibear9988 wants to merge 1 commit into
jogibear9988 wants to merge 1 commit into
Conversation
Server dispatch and session enqueue operations create packet bus items without waiting for delivery. When the pending-message queue overflows, Fail faults the item's completion task, which can later raise UnobservedTaskException even if the application handles the dropped-message notification. Observe the completion task's exception inside MqttPacketBusItem.Fail. This keeps the task faulted and preserves the original exception for existing and future WaitAsync callers, including DeliverApplicationMessageAsync. Add a garbage-collection regression test for failures without a waiter and verify that requesting the task before or after failure preserves the original overflow exception. Re-enable unobserved-exception tracking in the existing overflow integration tests for both drop strategies. Before the fix, the focused run failed the new unobserved-exception test and both enqueue overflow tests. After the fix, all nine focused cases and all 489 tests in the .NET 10 Release test suite pass. Fixes dotnet#2271
This branch has not been deployed
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.
When the server drops a queued message,
MqttPacketBusItem.Failfaults its completion task. Normal dispatch and session enqueue operations do not await that task, so the overflow can later reachTaskScheduler.UnobservedTaskExceptioneven when the application handles the dropped-message event.Observe the internal task's exception in
Failwhile leaving the task faulted. Existing and futureWaitAsynccallers still receive the original exception, including callers ofDeliverApplicationMessageAsync.Validation:
dotnet build MQTTnet.slnx --configuration Release: succeeds for .NET 8 and .NET 10, with 3 deprecation warnings in the unchanged benchmark project.Fixes #2271