Skip to content

Conversation

@mdaigle
Copy link
Contributor

@mdaigle mdaigle commented Nov 17, 2025

Description

When I originally implemented #3019, due to a misunderstanding about when connections are activated/deactivated, I added an extraneous call to DbConnectionInternal.DeactivateConnection as part of the PutObjectFromTransactedPool. Connections are always deactivated at the time they are returned to the pool via the ReturnInternalConnection method and do not need to be activated/deactivated as they move between the main pool and the transacted pool. The activate and deactivate methods modify a counter value that tracks the number of connections in active use. This extra deactivate led to active connection counts going negative.

However, removing this DeactivateConnection call is also not entirely correct. Part of the deactivation process is setting the "reset" flags via a call to the ResetConnection method. These flags determine the Status value sent to the server when a connection is recycled out of the pool. Connections that are placed in the transacted pool may use status RESETCONNECTIONSKIPTRAN if they are participating in a distributed transaction. This gives extra guarantees that the server will not reset the connection's transaction state. When moving a connection out of the transacted pool and back into the main pool, we no longer want the server to maintain the association to the transaction because the transaction has ended and we want to use the connection for general purpose commands. Therefore, we need to downgrade the connection's status value to RESETCONNECTION. This way, the next time the connection is used its association with the transaction will be removed.

To appropriately set the reset flags without impacting the active connection counter, I exposed the ResetConnection method as internal so that it can be called directly by the pool. All other actions taken in DeactivateConnection are safe to skip at this point.

I hope to clean up this flow as part of adding transaction support to the new pool implementation, but it's out of scope for this PR.

Issues

#3640

Testing

None of our tests cover metrics. Working on adding that as part of the new connection pool work.
In the meantime, this change will be verified manually.

Existing distributed transaction tests show that the reset flags are still reevaluated correctly.

Copilot AI review requested due to automatic review settings November 17, 2025 22:35
@mdaigle mdaigle changed the base branch from main to release/6.1 November 17, 2025 22:36
@mdaigle mdaigle added this to the 6.1.4 milestone Nov 17, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mdaigle mdaigle marked this pull request as ready for review November 17, 2025 23:33
@mdaigle mdaigle requested a review from a team as a code owner November 17, 2025 23:33
@priyankatiwari08 priyankatiwari08 self-assigned this Nov 18, 2025
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 65.86%. Comparing base (5200419) to head (488d937).
⚠️ Report is 3 commits behind head on release/6.1.

Files with missing lines Patch % Lines
.../Microsoft/Data/ProviderBase/DbConnectionClosed.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           release/6.1    #3776      +/-   ##
===============================================
- Coverage        66.69%   65.86%   -0.83%     
===============================================
  Files              279      279              
  Lines            61764    61765       +1     
===============================================
- Hits             41192    40681     -511     
- Misses           20572    21084     +512     
Flag Coverage Δ
addons 90.82% <ø> (ø)
netcore 68.56% <50.00%> (+0.02%) ⬆️
netfx 68.63% <50.00%> (-1.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@paulmedynski paulmedynski self-assigned this Nov 19, 2025
@mdaigle mdaigle merged commit b21442d into release/6.1 Nov 19, 2025
252 checks passed
@mdaigle mdaigle deleted the dev/mdaigle/6.1-active-connection-count branch November 19, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

number-of-active-connections metric goes negative, "activated multiple times?" debug assertions failing

5 participants