Repository navigation
[6.1.9 Cherry-pick] Fix managed SNI MARS receive teardown race - #4949
Open
github-actions[bot] wants to merge 3 commits into
Open
github-actions[bot] wants to merge 3 commits into
github-actions[bot] wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
To resolve, run: git cherry-pick 266a32e
* Fix managed SNI MARS receive teardown race Handle disposed TCP and named-pipe streams through SNI errors and preserve MARS packet ownership during receive re-arm failure. Add deterministic and SQL-backed regression coverage for #4679. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix MARS teardown callbacks and regression test hangs Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Address MARS teardown review feedback Keep consumed-packet cleanup outside the receive lock, add a lock-scope regression, and remove redundant manual-test collection isolation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
paulmedynski
force-pushed
the
dev/automation/pr-4680-to-6.1.9
branch
from
November 12, 2026 18:28
e867cfb to
8b19cac
Compare
paulmedynski
approved these changes
Nov 12, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The SNI guard incorrectly skips all eight regression cases on Linux/macOS under the default configuration, leaving the Unix managed-SNI path untested even when prerequisites are met.
1 open issue
What changed in this PR
Backports the managed SNI MARS receive teardown fix to release/6.1 for 6.1.9, addressing unobserved receive-continuation exceptions without changing public APIs.
Changes:
- Handle disposed TCP and named-pipe streams through existing SNI error paths.
- Preserve packet ownership during receive failures and notify only sessions with pending async reads.
- Adjust teardown assertions and add deterministic unit coverage plus a SQL-backed regression test. Live SQL scenarios were not executed locally.
| File | Description |
|---|---|
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ManagedSni/SniReceiveTests.cs |
Adds transport teardown, callback, and packet-ownership tests. |
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/MarsReceiveTeardownTest.cs |
Adds SQL-backed MARS teardown regression scenarios. |
src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj |
Includes the new manual regression test. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParserStateObject.cs |
Allows invalidated buffered-data estimates after closure in debug assertions. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs |
Reports disposed TCP streams through SNI errors. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs |
Guards named-pipe receives against disposed streams. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs |
Limits error callbacks to pending async receives. |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs |
Preserves error packets and releases incomplete payloads. |
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Parser/TdsParserStateObject.netcore.cs |
Allows valid late MARS error callbacks in debug assertions. |
Review effort: Balanced
| public static bool CanRun() | ||
| { | ||
| if (!DataTestUtility.AreConnStringsSetup() || | ||
| !DataTestUtility.IsNotAzureServer() || !DataTestUtility.IsUsingManagedSNI()) |
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.

Description
Backports #4680 (266a32e) to
release/6.1for 6.1.9. The failed cherry-pick is now resolved.Prevents unobserved receive-continuation exceptions during managed SNI MARS teardown by handling disposed transport streams, preserving packet ownership during receive re-arm failures, and notifying only sessions with pending async reads.
Release-specific adaptations retain the existing split parser layout, update the async callback assertion in its .NET-specific partial file, use the release branch's SNI error and timeout helpers, and explicitly include the SQL regression in the manual-test project. A test-local prerequisite check replaces the newer shared sysadmin helper.
No public API or intended compatibility changes.
Issues
Backport of #4680 for #4679.
Testing
Using a session-local .NET SDK 9.0.312, with the restored x64 native SNI DLL copied into generated test outputs:
Passed: 58, failed: 0, including all 25 backported teardown cases.
Build passed; regression theory discovered and skipped because its SQL Server/managed-SNI/sysadmin prerequisites were not configured. Live SQL integration scenarios were not executed. NuGet auditing was disabled only for local validation because the NuGet.org vulnerability service was unreachable; repository settings are unchanged.
Guidelines
Please review the contribution guidelines before submitting a pull request:
Contributing
Code of Conduct
Best Practices
Coding Style
Review Process
Tests added or updated
Public API changes documented (none)
Verified against customer repro (not available locally)
Ensure no breaking changes introduced