Skip to content

SNI: Fix managed networking deadlocks on single-worker schedulers - #5147

Open
paulmedynski wants to merge 2 commits into
mainfrom
dev/automation/fix-single-worker-pool-hang
Open

paulmedynski wants to merge 2 commits into
mainfrom
dev/automation/fix-single-worker-pool-hang

Conversation

@paulmedynski

@paulmedynski paulmedynski commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix two managed SNI deadlocks when opening a connection on a single-worker scheduler:

  • Run parallel SQL Browser (SSRP) requests on TaskScheduler.Default. The original CI dump confirms the caller was waiting for a request queued on its own blocked scheduler.
  • Prevent Strict-TLS authentication from capturing that scheduler with ConfigureAwait(false). A separate regression reproduces this deadlock before the fix.

Add SSRP response/timeout and sync/async TLS regressions. No public API, pooling, timeout, or quarantine changes.

Issues

The regression added in #5119 (backported in #5130) exposed the pre-existing driver bug. Original hang: MDS Main CI 195012.

Testing

  • Before fixes: all three SSRP cases timed out; the synchronous Strict-TLS case hung beyond its connection timeout.
  • Windows: 9 passed, none skipped. $dll is the built Release/net10.0 unit-test assembly:
dotnet vstest $dll "--TestCaseFilter:FullyQualifiedName~SsrpClientTests|FullyQualifiedName~TlsHandshakeTimeoutTests" "--logger:console;verbosity=normal"
  • Linux: 7 passed (six TLS cases and SSRP timeout). The two UDP response cases failed in WSL; an independent loopback UDP probe also failed. Both cases pass on Windows.
  • net462/net10.0 build: passed, zero warnings/errors:
dotnet build src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj -c Release --no-restore -v:q

Full MDS Main CI run 195040 is queued against this PR's commit to validate the original test. Real-SQL validation remains pending; failed Strict-TLS mock login attempts are not counted as passes.

  • Tests added or updated
  • Public API changes documented (no public API changes)
  • Verified against customer repro (if applicable; real SQL/CI rerun remains pending)
  • Ensure no breaking changes introduced

Guidelines

Please review the contribution guidelines before submitting a pull request:

Run parallel SQL Browser requests on the default scheduler so a caller blocked in Task.WaitAny cannot starve its own request workers. Keep Strict TLS authentication completion independent of the caller's scheduler as well, preventing a follow-on deadlock after instance discovery.

Add focused SSRP response/timeout and synchronous/asynchronous Strict TLS regressions. The original Windows CI dump confirms the SSRP scheduler cycle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 18:02
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Nov 25, 2026
@paulmedynski paulmedynski added this to the 8.1.0-preview1 milestone Nov 25, 2026
@paulmedynski paulmedynski added the Hotfix 8.0.0 PRs that must be backported to release/8.0 label Nov 25, 2026
@paulmedynski paulmedynski moved this from To triage to In progress in SqlClient Board Nov 25, 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.

🔵 Needs a closer look

The Windows named-instance/Strict-encryption pool regression still lacks a real SQL Server CI rerun validating discovery, TLS login, and pooled connection reuse under the single-worker scheduler.

No open issues 🎉

What changed in this PR

Fixes two managed SNI deadlocks when a connection opens on a single-worker scheduler: SQL Browser discovery workers and Strict TLS authentication continuations no longer depend on the blocked caller’s scheduler.

Changes:

  • Runs parallel SQL Browser requests explicitly on TaskScheduler.Default.
  • Prevents scheduler capture during TLS authentication with ConfigureAwait(false).
  • Adds SQL Browser response/timeout tests and separate synchronous/asynchronous Strict TLS scheduler regressions.

Public APIs, pooling behavior, timeouts, and quarantine status remain unchanged. The real SQL Server named-instance CI rerun remains pending.

File Description
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​TlsHandshakeTimeoutTests.cs Adds sync and async Strict TLS single-worker scheduler regressions.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​ManagedSni/​SsrpClientTests.cs Adds SQL Browser response and silent-peer timeout scheduler tests.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SsrpClient.netcore.cs Schedules parallel discovery workers independently of the caller.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniHandle.netcore.cs Avoids scheduler capture in the TLS authentication helper.

Review effort: Balanced

@paulmedynski paulmedynski added Hotfix 6.1.9 PRs targeting main that should be backported to release/6.1 for 6.1.9. Hotfix 7.0.5 PRs targeting main that should be backported to release/7.0 for 7.0.5 Hotfix 7.1.3 PRs targeting main that should be backported to release/7.1 for 7.1.3. labels Nov 25, 2026
@paulmedynski
paulmedynski marked this pull request as ready for review November 25, 2026 18:16
@paulmedynski
paulmedynski requested a review from a team as a code owner November 25, 2026 18:16
@paulmedynski paulmedynski moved this from In progress to In review in SqlClient Board Nov 25, 2026
Isolate scheduler-sensitive SSRP tests from unrelated blocking collections, match DateTime conversion errors using runtime en-US formatting, and preserve platform exclusions in flaky-test runs. Document the trait-based platform filtering contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 20:42

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.

🟡 Changes recommended

The PR description omits the CI behavior change excluding tests tagged both flaky and failing and needs to document that change and its regression coverage.

1 open issue

Review effort: Balanced

-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.51%. Comparing base (17bef7b) to head (e19a84b).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5147      +/-   ##
==========================================
+ Coverage   68.99%   70.51%   +1.51%     
==========================================
  Files         314      315       +1     
  Lines       45857    70161   +24304     
==========================================
+ Hits        31638    49471   +17833     
- Misses      14219    20690    +6471     
Flag Coverage Δ
CI-SqlClient ?
sqlclient-pr 70.51% <100.00%> (?)

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.

-p:PackageVersionSqlClient=${{ parameters.packageVersion }}
-p:PackageVersionSqlServer=${{ parameters.sqlServerPackageVersion }}
-p:TestFilters="category=flaky"
-p:TestFilters="category=flaky&category!=failing"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the intention of the change is to avoid running failing tests in the Flaky tests step. Failing would always fail so not excluding them in the first place with Flaky tests was a wrong choice, is that correct ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two unexpected things converged here:

  • We, as test authors, never intended to have the "flaky" and "failing" traits applied to a test at the same time - it's one or the other, so the filters never accounted for that.
  • The XUnitExtensions [PlatformSpecific] attribute injects a "failing" trait onto tests whose required platform doesn't match the runtime. Yowzers!

The surprising [PlatformSpecific] implementation coufounded our original assumption, and now we must explicitly exclude "failing" everywhere, because it no longer means "tests we explicitly marked as failing". It has been expanded to include "tests that shouldn't run on this platform". Perhaps upgrading to xUnit3 will help with situations like this since it has a richer filtering engine.

@saurabh500

Copy link
Copy Markdown
Collaborator

What a find !

I have left a curiosity comment, please resolve after providing the response. Do not wait for me

@paulmedynski
paulmedynski enabled auto-merge (squash) November 25, 2026 23:58

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

Hotfix 6.1.9 PRs targeting main that should be backported to release/6.1 for 6.1.9. Hotfix 7.0.5 PRs targeting main that should be backported to release/7.0 for 7.0.5 Hotfix 7.1.3 PRs targeting main that should be backported to release/7.1 for 7.1.3. Hotfix 8.0.0 PRs that must be backported to release/8.0

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

7 participants