Skip to content

WaitHandleDbConnectionPool: reclaimed connections never emit a soft disconnect, so activeSoftConnections drifts #4555

Closed

Description

@mdaigle

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.

Activity

  1. added theissue type on Aug 19, 2026
  2. added
    Area\Connection Pooling
    on Aug 19, 2026
  3. github-actions commented on Aug 19, 2026

    @github-actions

    🔍 Triage Summary

    Check Result
    Issue type Bug
    Environment 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.

    Generated by SqlClient Issue Auto-Triage for issue #4555 · 28.4 AIC · ⌖ 6.38 AIC · ⊞ 8.6K · ◷

  4. moved this from To triage to Backlog in SqlClient Boardon Aug 19, 2026
  5. moved this from Backlog to In progress in SqlClient Boardon Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area\Connection Pooling

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions