Visitar URL original
Fix MultiSubnetFailover parallel connect when one address fails immediately by cheenamalhotra · Pull Request #4929 · dotnet/SqlClient · GitHub
Skip to content

Fix MultiSubnetFailover parallel connect when one address fails immediately - #4929

Merged
cheenamalhotra merged 2 commits into
mainfrom
dev/cheena/parallel-connect-fix
Oct 30, 2026
Merged

cheenamalhotra merged 2 commits into
mainfrom
dev/cheena/parallel-connect-fix

Conversation

@cheenamalhotra

Copy link
Copy Markdown
Member

Description

With MultiSubnetFailover=true, managed SNI ParallelConnect failed the whole connection when one resolved address errored immediately (e.g. no IPv6 route), even if another address was reachable. Already-created sockets were also not disposed.

  • Catch per-address SocketException, record it, and keep trying the remaining addresses.
  • Dispose all non-selected sockets in a finally block.
  • Make ParallelConnect internal for unit tests.

Most of the diff is re-indentation; use git diff -w to see the logic change (~40 lines).

  • Tests added or updated
  • Public API changes documented (none)
  • Verified against customer repro (no customer repro supplied)
  • Ensure no breaking changes introduced

Issues

Fixes #4928. Related: #4876, #4927.

Testing

Passed, 30 tests (macOS, net10.0). The new good+bad address cases fail on the old code (3 failures) and pass with the fix.

dotnet test src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj --framework net10.0 --filter 'FullyQualifiedName~SniTcpHandleParallelConnectTests|FullyQualifiedName~ConnectionRoutingTests|FullyQualifiedName~MultiSubnetFailover'

git diff --check: passed. Windows/Linux not run locally.

Guidelines

Please review the contribution guidelines before submitting a pull request:

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@cheenamalhotra
cheenamalhotra requested a review from a team as a code owner October 27, 2026 17:19
Copilot AI balanced review requested due to automatic review settings October 27, 2026 17:19
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Oct 27, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

Reported testing covers macOS, but platform-dependent socket behavior and cleanup still need Windows/Linux validation before approval.

No open issues 🎉

What changed in this PR

Fixes #4928 by allowing managed SNI parallel connections to continue when one address fails immediately, supporting the planned MultiSubnetFailover default change.

Changes:

  • Records per-address socket failures and continues trying remaining addresses.
  • Moves socket cleanup into finally to dispose non-selected sockets on normal and exceptional exits.
  • Exposes ParallelConnect internally and adds regression tests for mixed reachable/unreachable addresses and connection failure.
File Description
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniTcpHandleParallelConnectTests.cs Adds mixed-address success and all-addresses-fail tests.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​ManagedSni/​SniTcpHandle.netcore.cs Handles immediate per-address failures and ensures socket cleanup.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 17:22

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

Platform-dependent socket handling still needs Windows/Linux validation and confirmed passing CI before human approval.

No open issues 🎉

Review effort: Balanced

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.15%. Comparing base (7b1184b) to head (e154df8).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
.../Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs 85.71% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4929      +/-   ##
==========================================
- Coverage   67.94%   66.15%   -1.80%     
==========================================
  Files         311      305       -6     
  Lines       45399    68317   +22918     
==========================================
+ Hits        30845    45193   +14348     
- Misses      14554    23124    +8570     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 66.15% <85.71%> (?)

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.

@priyankatiwari08 priyankatiwari08 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.

Looks good — no concerns.

@cheenamalhotra
cheenamalhotra merged commit cb66150 into main Oct 30, 2026
125 of 126 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Oct 30, 2026
@cheenamalhotra
cheenamalhotra deleted the dev/cheena/parallel-connect-fix branch October 30, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MultiSubnetFailover parallel connect fails if one address errors immediately (managed SNI)

6 participants