Why is my database connection pool draining and not releasing connections?
#1
I’ve been trying to get my head around a persistent issue where my application’s database connection pool seems to drain for no clear reason. The logs show connections are being established but never released back, even though I’m sure I’m closing them properly in the code. It’s like they’re stuck in a weird state that doesn’t trigger a timeout.
Reply
#2
I’ve chased something similar. A few times I saw the pool fill up because a thread kept a connection open with an open transaction. The log would show new connections, then nothing returning to idle. It wasn’t a timeout issue so much as a code path that didn’t close the transaction or release the connection in all branches.
Reply
#3
I tried turning on leak detection and tightening max lifetime, plus a guard that forces a release after migrations or background tasks. It helped a bit, but there were a couple cases where a listener kept a Connection object referenced in a static cache and that stalled the release.
Reply
#4
Do you have any background jobs or cron tasks that might grab a connection and never give it back?
Reply
#5
Sometimes I feel like the logs lie a bit; they show new connections but maybe the release is happening and the pool just isn’t updating correctly due to a metric bug. I tried a tiny local repro and restarting the pool seemed to reduce the drain, but that isn’t a real fix.
Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Forum Jump: