postgres-nio icon indicating copy to clipboard operation
postgres-nio copied to clipboard

Fix Connection Pool crash when requests are waiting while timer is triggered

Open lovetodream opened this issue 1 year ago • 0 comments

When connections are requested from the pool in bursts, the pool might have requests in the queue while a keep alive or idle timer is triggered. This should resolve the issue, closes #472.

Currently, I've only implemented a test case to reproduce the behaviour. (The test case is a bit verbose atm, but I wanted to include the full picture for now) One way to fix it would be to check the request queue in PoolStateMachine.connectionKeepAliveTimerTriggered(_:) and PoolStateMachine.connectionIdleTimerTriggered(_:) instead of a precondition. This can be archived by calling PoolStateMachine.handleAvailableConnection(index:availableContext:) if the queue is not empty. Maybe this should be handled in ConnectionPool instead?

Let me know what you think @fabianfett

lovetodream avatar May 09 '24 11:05 lovetodream