Skip to content

Repro Test for #3720 (Unobserved Exception) - #4460

Merged
benrr101 merged 6 commits into
mainfrom
dev/russellben/3720-unobserved
Jul 28, 2026
Merged

Repro Test for #3720 (Unobserved Exception)#4460
benrr101 merged 6 commits into
mainfrom
dev/russellben/3720-unobserved

Conversation

@benrr101

Copy link
Copy Markdown
Contributor

Description

This PR provides a reliable reproduction of #3720 in which an exception produced by the AsyncIOCompletionCallback of the SNI Packet class is not observed, leading to the unobserved exception handler being invoked.

This PR does not attempt to fix the issue, just adds a test that can be used to verify that the behavior exists. Attempts to fix the issue will inherently break this test, but can easily be fixed by changing the single assert in the test from "IsNotNull" to "IsNull".

Issues

#3720

Testing

Ran for hundreds of iterations with no failures observed.

@benrr101 benrr101 added this to the 7.1.0-preview3 milestone Jul 20, 2026
@benrr101
benrr101 requested a review from a team as a code owner July 20, 2026 23:05
@benrr101 benrr101 added the Area\Tests Issues that are targeted to tests or test projects label Jul 20, 2026
Copilot AI review requested due to automatic review settings July 20, 2026 23:05
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Jul 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit-test infrastructure and a targeted repro test for issue #3720, demonstrating that exceptions thrown from SniPacket’s async IO completion callback can go unobserved and later surface via TaskScheduler.UnobservedTaskException.

Changes:

  • Introduces a shared ObservableException test utility to uniquely tag unobserved exceptions.
  • Refactors AsyncHelperTest to use the shared ObservableException instead of an inline nested type.
  • Adds a new Managed SNI unit test that reliably reproduces the unobserved-exception behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/Microsoft.Data.SqlClient/tests/UnitTests/Utilities/ObservableException.cs Adds a reusable exception type for unobserved-exception testing scenarios.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/Utilities/AsyncHelperTest.cs Removes the inline ObservableException in favor of the shared utility type.
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ManagedSni/SniPacketAsyncCallbackTest.cs Adds a repro test for unobserved exceptions originating from SniPacket async callbacks.

Comment thread src/Microsoft.Data.SqlClient/tests/UnitTests/Utilities/ObservableException.cs Outdated
Comment thread src/Microsoft.Data.SqlClient/tests/UnitTests/Utilities/ObservableException.cs Outdated
@paulmedynski paulmedynski moved this from To triage to In review in SqlClient Board Jul 21, 2026

@paulmedynski paulmedynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking on Copilot feedback. My suggestion about ObservableException is at your discretion.

Comment thread src/Microsoft.Data.SqlClient/tests/UnitTests/Utilities/ObservableException.cs Outdated
@github-project-automation github-project-automation Bot moved this from In review to Waiting for customer in SqlClient Board Jul 21, 2026
Copilot AI review requested due to automatic review settings July 21, 2026 20:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ManagedSni/SniPacketTests.cs:47

  • The unobserved-exception filter is currently using InnerExceptions.Contains(testException), which relies on reference equality. This makes the test more brittle and also diverges from the ObservableException remarks and existing AsyncHelperTest pattern (match by Identifier). Consider matching ObservableException.Identifier instead (without LINQ, per prior discussion).
            EventHandler<UnobservedTaskExceptionEventArgs> handleUnobservedException =
                (_, args) =>
                {
                    if (args.Exception.InnerExceptions.Contains(testException))
                    {
                        args.SetObserved();
                        unobservedExceptionRaised.TrySetResult(args.Exception);
                    }
                };

Comment thread src/Microsoft.Data.SqlClient/tests/UnitTests/Utilities/ObservableException.cs Outdated
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.59%. Comparing base (fdebcd2) to head (de23155).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4460      +/-   ##
==========================================
- Coverage   65.83%   62.59%   -3.25%     
==========================================
  Files         287      283       -4     
  Lines       43763    67285   +23522     
==========================================
+ Hits        28812    42114   +13302     
- Misses      14951    25171   +10220     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 62.59% <ø> (?)

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

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI review requested due to automatic review settings July 22, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 22, 2026 23:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@cheenamalhotra cheenamalhotra moved this from Waiting for customer to In review in SqlClient Board Jul 23, 2026
@benrr101
benrr101 merged commit f5be62b into main Jul 28, 2026
359 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Jul 28, 2026
@benrr101
benrr101 deleted the dev/russellben/3720-unobserved branch July 28, 2026 20:57
mdaigle added a commit that referenced this pull request Jul 28, 2026
Brings in the completed connection-pool pruning work (Story 2/3/4, #4463),
which reworks PoolPruner to be driven by Connection Idle Timeout and only
constructs a Pruner when IdleTimeout != 0. The single overlapping file,
ChannelDbConnectionPool.cs, auto-merged cleanly: main's constructor pruner
block coexists with this branch's ReplaceConnection additions. Also pulls in
#4460 (unobserved-exception repro), #4347 (vector test refactor), and #4459
(pool benchmark coverage).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Tests Issues that are targeted to tests or test projects

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants