Fix classification of disposal-during-reconnect as cancelled, not failed#592
Open
jpablo2002 wants to merge 3 commits intomainfrom
Open
Fix classification of disposal-during-reconnect as cancelled, not failed#592jpablo2002 wants to merge 3 commits intomainfrom
jpablo2002 wants to merge 3 commits intomainfrom
Conversation
added 2 commits
March 27, 2026 14:30
…and fixed event logging of reconnect failed vs cancelled to warn correctly.
…eported correctly
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
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.
Problem
We currently see multiple
host_reconnect_failederrors withObjectDisposedException: RelayTunnelConnector is disposed. These are logged at error severity and pollute dashboards, but they are not actual reconnect failures — the host application calledDisposeAsync()while the SDK's reconnect retry loop was in flight, cancelling it.The causal chain is:
Closedevent firesReconnectAsync(DisposeToken)as a background taskMaybeStartReconnectingsetsConnectionStatus = Connecting, which firesConnectionStatusChangedsynchronously to the host appawait usingscope →DisposeAsync()is calledDisposeAsync()cancelsdisposeCts→DisposeTokencancelled → reconnect retry loop abortedOperationCanceledExceptionis wrapped asObjectDisposedExceptionbyTryAdjustCancellationReconnectAsynccatches it and reportshost_reconnect_failedat error severity — indistinguishable from a genuine failureFix
In
ReconnectAsync, check whether the exception was caused by disposal-cancellation before choosing the event name and severity:DisposeToken.IsCancellationRequestedANDex is ObjectDisposedException or OperationCanceledException→ reporthost_reconnect_cancelledat warning severityhost_reconnect_failedat error severity (unchanged)Both conditions must be true to classify as cancelled. If
DisposeAsync()was called but the reconnect had already failed with a real error (e.g.WebSocketException,UnauthorizedAccessException), the exception type won't match and it's correctly reported as a failure.Files Changed
cs/src/Connections/TunnelRelayConnection.cs—ReconnectAsynccatch block now distinguishes disposal-cancelled from genuine failure when reporting telemetry eventscs/test/TunnelsSDK.Test/Mocks/MockTunnelManagementClient.cs—ReportEventnow captures events in aReportedEventslist for test assertionscs/test/TunnelsSDK.Test/TunnelHostAndClientTests.cs— two new tests:DisposeDuringReconnectReportsCancelledEvent— verifies disposal during reconnect reports_reconnect_cancelled(warning)ReconnectFailureReportsFailedEvent— verifies a genuine reconnect failure reports_reconnect_failed(error)