Repository navigation
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the disposed-connection send fix and its associated regression tests.
No open issues 🎉
What changed in this PR
This PR fixes managed-SNI synchronous TCP sends after connection disposal, preventing a null-reference exception during MARS teardown and reporting a connection error instead.
Changes:
- Capture and validate the stream within the existing send exception handler.
- Add disposal-before-send tests for ordinary and out-of-band packets, plus a healthy-send control that checks data delivery and packet ownership.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandleSendTests.cs | Adds disposed-send regressions and healthy-send coverage. |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs | Routes a cleared stream through existing disposed-connection error handling. |
Review effort: Balanced
mdaigle
marked this pull request as ready for review
November 13, 2026 18:54
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5067 +/- ##
==========================================
+ Coverage 68.99% 69.96% +0.97%
==========================================
Files 314 314
Lines 45857 69822 +23965
==========================================
+ Hits 31638 48854 +17216
- Misses 14219 20968 +6749
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
🤖 This pull request was created by a fully automated workflow.
Description
Fix a managed-SNI send-side teardown error exposed when a streaming MARS reader sends an ACK after the physical TCP handle has been disposed.
Disposeclears_stream;Sendpreviously passed that null reference toSniPacket.WriteToStream, leakingNullReferenceExceptioninstead of reporting a connection error.Capture and validate the stream inside the existing send exception handler. A disposed transport now follows the existing
ObjectDisposedExceptiontracing and SNI error path. Locking, attention handling, asynchronous send behavior, packet ownership and public APIs are unchanged. No dependencies, localization, pipeline definitions or test categories change.Issues
Addresses the send-side failure reported in #49, closed for lack of a reproduction. No duplicate issue was opened. The current individual CI failure is
MarsReceiveTeardownTest.FatalError_WhileMarsReaderStreams_DoesNotFaultReceivePump(async: False, pooling: True, delay: 29)on Linux/net10.0 managed SNI.Testing
Added a controlled disposal-before-send regression for ordinary and out-of-band packets, plus a healthy-send control. Before correction, both disposed cases failed with the same
SniPacket.WriteToStreamnull dereference; the healthy control passed. This reproduces the transport ownership violation without relying on the integration test's scheduling.Passed: 33 tests, zero failures/skips, on Windows/.NET 10 in both Release and Debug (omit
-c Release).--list-testsverified all three new cases. Existing receive tests cover synchronous and asynchronous teardown paths.Passed: all eight original integration cases, zero skipped, with Windows managed SNI and SQL Server 17.0.1155.3. Temporary configuration selected localhost/master, integrated authentication and
UseManagedSNIOnWindows=true; no credentials were stored.dotnet build src\Microsoft.Data.SqlClient\src\Microsoft.Data.SqlClient.csproj --no-restore -f net462 -c Release -v:q— passed, zero warnings/errors. The .NET Framework/native SNI implementations are unchanged.Scoped Linux CI succeeded on the exact repair SHA below, Debug/Project, .NET 10 managed SNI, attempt 1 (2026-11-13 UTC). Individually verified all three new unit cases and all eight original integration cases, including the previously failing case. Result totals reconcile: 2,560 unit and 1,239 integration passes; 18/127 unrelated not-executed results are not counted as coverage. One passing matrix run does not establish indefinite race stability.
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 (original CI test passes locally and in Linux CI; controlled transport regression fails before/passes after)
Ensure no breaking changes introduced