WaitHandleDbConnectionPool: reclaimed connections never emit a soft disconnect, so activeSoftConnections drifts
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
`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.
Contributor guide
Research direction
Start in WaitHandleDbConnectionPool.ReclaimEmancipatedObjects and compare its reclamation path with the ChannelDbConnectionPool fix in #4529. Review DbConnectionPoolInstrumentationTest.EmancipatedConnection_IsReclaimedAndCounted, then route reclamation through the appropriate accounting path while preserving the lock and sweep behavior. Done means the test has one corrected expectation and activeSoftConnections remains accurate after leak-and-reuse cycles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100