You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WaitHandleDbConnectionPool: reclaimed connections never emit a soft disconnect, so activeSoftConnections drifts #4555
WaitHandleDbConnectionPool.ReclaimEmancipatedObjects returns a leaked connection to the pool without emitting the matching soft disconnect, so activeSoftConnections (NumberOfActiveConnections) drifts up by one per leaked connection and never recovers.
A checkout emits Metrics.SoftConnectRequest(). The matching Metrics.SoftDisconnectRequest() lives only in ReturnInternalConnection, which reclamation bypasses: the reclaim loop calls DeactivateObject directly. The connection is then re-vended and counted again, so the gauge climbs on every leak-and-reuse cycle even though only one connection is checked out.
ChannelDbConnectionPool had the same hole. #4529 fixes it there by routing reclamation through ReturnInternalConnection instead of calling the deactivate/route helper directly, which puts the accounting in one place. The same approach should work here, though ReclaimEmancipatedObjects calls PrePush inside the lock (_objectList) scan, so it needs the equivalent of #4529's sweep gate before the claim can move into ReturnInternalConnection.
DbConnectionPoolInstrumentationTest.EmancipatedConnection_IsReclaimedAndCounted covers both pools and currently asserts the drift for WaitHandle and the corrected value for Channel. Fixing this should collapse it back to one expectation.
Not urgent: it only affects a diagnostic counter, and only for applications that already leak connections.
All required environment details provided for investigation
Area
Area\Connection Pooling
Duplicates
Related: #4529 (the ChannelDbConnectionPool fix this issue mirrors)
Regression
Not indicated — diagnostic counter drift, not a functional regression
Analysis
WaitHandleDbConnectionPool.ReclaimEmancipatedObjects re-activates leaked connections by calling DeactivateObject directly, skipping ReturnInternalConnection which is where Metrics.SoftDisconnectRequest() is emitted. Every leak-and-reuse cycle therefore increments activeSoftConnections without a corresponding decrement, causing the NumberOfActiveConnections performance counter to drift upward permanently. The same issue was fixed for ChannelDbConnectionPool in #4529 by routing reclamation through ReturnInternalConnection; this bug is the WaitHandleDbConnectionPool equivalent. Severity: P3 — affects only a diagnostic counter, only for applications that already leak connections.
Next Steps
Assign to Copilot coding agent to investigate WaitHandleDbConnectionPool.ReclaimEmancipatedObjects in src/Microsoft.Data.SqlClient/src/ and apply the same approach used in Channel Pool: Reclaim leaked connections #4529: route reclamation through ReturnInternalConnection instead of calling the deactivate helper directly (mindful that the existing PrePush call inside the lock (_objectList) scan may need a sweep-gate equivalent before the lock is released).
The existing test DbConnectionPoolInstrumentationTest.EmancipatedConnection_IsReclaimedAndCounted already exercises both pools; once the fix is applied it should have a single shared expectation for both pool types.
Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.
Activity
github-actions commentedon Aug 19, 2026
🔍 Triage Summary
Area\Connection PoolingChannelDbConnectionPoolfix this issue mirrors)Analysis
WaitHandleDbConnectionPool.ReclaimEmancipatedObjectsre-activates leaked connections by callingDeactivateObjectdirectly, skippingReturnInternalConnectionwhich is whereMetrics.SoftDisconnectRequest()is emitted. Every leak-and-reuse cycle therefore incrementsactiveSoftConnectionswithout a corresponding decrement, causing theNumberOfActiveConnectionsperformance counter to drift upward permanently. The same issue was fixed forChannelDbConnectionPoolin #4529 by routing reclamation throughReturnInternalConnection; this bug is theWaitHandleDbConnectionPoolequivalent. Severity: P3 — affects only a diagnostic counter, only for applications that already leak connections.Next Steps
WaitHandleDbConnectionPool.ReclaimEmancipatedObjectsinsrc/Microsoft.Data.SqlClient/src/and apply the same approach used in Channel Pool: Reclaim leaked connections #4529: route reclamation throughReturnInternalConnectioninstead of calling the deactivate helper directly (mindful that the existingPrePushcall inside thelock (_objectList)scan may need a sweep-gate equivalent before the lock is released).DbConnectionPoolInstrumentationTest.EmancipatedConnection_IsReclaimedAndCountedalready exercises both pools; once the fix is applied it should have a single shared expectation for both pool types.Route reclamation through ReturnInternalConnection
Channel Pool: Reclaim leaked connections (#4529)