Visitar URL original
[6.1.9 Cherry-pick] Fix managed SNI MARS receive teardown race by github-actions[bot] · Pull Request #4949 · dotnet/SqlClient · GitHub
Skip to content

[6.1.9 Cherry-pick] Fix managed SNI MARS receive teardown race - #4949

Open
github-actions[bot] wants to merge 3 commits into
release/6.1from
dev/automation/pr-4680-to-6.1.9
Open

github-actions[bot] wants to merge 3 commits into
release/6.1from
dev/automation/pr-4680-to-6.1.9

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Description

Backports #4680 (266a32e) to release/6.1 for 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:

dotnet test src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj -f net9.0 -r win-x64 --no-build --no-restore --filter 'FullyQualifiedName~ManagedSni|FullyQualifiedName~TdsParserStateObjectNativeTests' --verbosity quiet --blame-hang-timeout 2m

Passed: 58, failed: 0, including all 25 backported teardown cases.

dotnet test src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj -f net9.0 --filter FullyQualifiedName~MarsReceiveTeardownTest --verbosity quiet --blame-hang-timeout 2m -p:NuGetAudit=false

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:

@github-actions github-actions Bot added this to the 6.1.9 milestone Oct 30, 2026
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Oct 30, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@cheenamalhotra cheenamalhotra changed the title [6.1.9 Cherry-pick - CONFLICTS] Fix managed SNI MARS receive teardown race [6.1.9 Cherry-pick] Fix managed SNI MARS receive teardown race Oct 30, 2026
github-actions Bot and others added 3 commits November 12, 2026 14:26
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
paulmedynski force-pushed the dev/automation/pr-4680-to-6.1.9 branch from e867cfb to 8b19cac Compare November 12, 2026 18:28
@paulmedynski
paulmedynski marked this pull request as ready for review November 12, 2026 18:46
@paulmedynski
paulmedynski requested a review from a team as a code owner November 12, 2026 18:46
Copilot AI balanced review requested due to automatic review settings November 12, 2026 18:46

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 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

4 participants