Skip to content

Fix unobserved task exceptions when pending messages overflow - #2272

Open
jogibear9988 wants to merge 1 commit into
dotnet:masterfrom
jogibear9988:codex/fix-pending-message-overflow
Open

jogibear9988 wants to merge 1 commit into
dotnet:masterfrom
jogibear9988:codex/fix-pending-message-overflow

Conversation

@jogibear9988

Copy link
Copy Markdown

When the server drops a queued message, MqttPacketBusItem.Fail faults its completion task. Normal dispatch and session enqueue operations do not await that task, so the overflow can later reach TaskScheduler.UnobservedTaskException even when the application handles the dropped-message event.

Observe the internal task's exception in Fail while leaving the task faulted. Existing and future WaitAsync callers still receive the original exception, including callers of DeliverApplicationMessageAsync.

  • Add a regression test that collects a failed packet task without awaiting it and checks for unobserved exceptions.
  • Verify that requesting the task before or after failure preserves the original overflow exception.
  • Re-enable unobserved-exception tracking in the existing overflow tests for both drop strategies.

Validation:

  • Before the fix, the focused run fails the new regression test and both enqueue overflow tests (3 failures).
  • After the fix, all 9 focused tests pass.
  • Full .NET 10 Release suite: 489 passed, 0 failed, 0 skipped.
  • dotnet build MQTTnet.slnx --configuration Release: succeeds for .NET 8 and .NET 10, with 3 deprecation warnings in the unchanged benchmark project.

Fixes #2271

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

No deployments
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.

Server: MqttPendingMessagesOverflowException reaches TaskScheduler.UnobservedTaskException

1 participant