Skip to content

ChannelDbConnectionPool replace connection#4429

Draft
mdaigle wants to merge 12 commits into
mainfrom
dev/mdaigle/replace-conn-2
Draft

ChannelDbConnectionPool replace connection#4429
mdaigle wants to merge 12 commits into
mainfrom
dev/mdaigle/replace-conn-2

Conversation

@mdaigle

@mdaigle mdaigle commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Provide a summary of the changes being introduced. Important topics to cover
include:

  • Description of the functionality.
  • API changes, backwards compatibility, deprecations, etc.
  • Documentation, localization.
  • Bug fixes.
  • Code hygiene, refactoring, improvements.
  • Engineering processes (CI, pipelines, test coverage)

High quality descriptions will lead to a smoother review experience.

Issues

Link to any relevant issues, bugs, or discussions (e.g., Closes #123, Fixes issue #456).

Testing

Describe the automated tests (unit, integration) you created or modified.
Provide justification for any gap in automated testing. List any manual testing
steps that were performed to ensure the changes work. 

Guidelines

Please review the contribution guidelines before submitting a pull request:

Copilot AI review requested due to automatic review settings July 8, 2026 01:50
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Jul 8, 2026
@mdaigle mdaigle changed the title Dev/mdaigle/replace conn 2 ChannelDbConnectionPool replace connection Jul 8, 2026
@mdaigle mdaigle added this to the 7.1.0-preview3 milestone Jul 8, 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.

Pull request overview

Implements connection replacement support for the channel-based connection pool, including a new slot-level atomic replace operation and expanded unit test coverage around replacement behavior.

Changes:

  • Implement ChannelDbConnectionPool.ReplaceConnection(...) and introduce internal replacement acquisition logic (idle-preferred, otherwise create new).
  • Add ConnectionPoolSlots.TryReplace(...) to atomically swap a connection within an existing reserved slot.
  • Update/extend unit tests, including a new dedicated ChannelDbConnectionPoolReplaceConnectionTest suite and an updated existing replacement test.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ConnectionPoolSlotsTest.cs Adds new tests validating ConnectionPoolSlots.TryReplace behaviors.
src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolTest.cs Updates the existing replace-connection test to exercise the new implementation.
src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolReplaceConnectionTest.cs Adds a new test file covering replacement scenarios (idle preference, capacity behavior, failure propagation).
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/IDbConnectionPool.cs Changes ReplaceConnection return type to nullable.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ConnectionPoolSlots.cs Adds TryReplace helper to atomically swap a connection in-place.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs Implements ReplaceConnection, adds replacement acquisition logic, and updates PrepareConnection to accept an optional transaction.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.59184% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.07%. Comparing base (fdebcd2) to head (2f880ce).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...qlClient/ConnectionPool/ChannelDbConnectionPool.cs 75.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4429      +/-   ##
==========================================
- Coverage   65.83%   64.07%   -1.77%     
==========================================
  Files         287      282       -5     
  Lines       43763    66706   +22943     
==========================================
+ Hits        28812    42741   +13929     
- Misses      14951    23965    +9014     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 64.07% <79.59%> (?)

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.

Copilot AI review requested due to automatic review settings July 10, 2026 00:02

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Comment on lines +276 to +282
if (!replaced)
{
// This should never happen because oldConnection is checked out and its slot is stable.
// Still, we need to check or we could vend a connection that is not tracked by the pool.
// TODO: error types and localization
throw new InvalidOperationException("Connection is no longer in the pool and cannot be replaced.");
}
Comment on lines +316 to +321
/// <summary>
/// Verifies that when activating the replacement connection fails, the newly created
/// connection is returned to the pool rather than leaked, keeping the pool count stable.
/// </summary>
[Fact]
public void ReplaceConnection_ActivationFails_NewConnectionReturnedToPool()
Comment on lines +354 to +357
// Assert — the new connection was returned to pool (not leaked).
// Pool count stays same because the new connection replaced the old one's slot
// and was then returned to idle.
Assert.Equal(countBefore, pool.Count);
Comment on lines +364 to +365
// NOTE: Preferring an idle connection over a new physical one is being added in a follow-up PR
// (branch dev/automation/replace-conn-idle-path), along with its ReplaceConnection_PrefersIdleOverNewConnection test.
Comment on lines 704 to 706
[Fact]
public void TestReplaceConnection()
{
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.

2 participants