Connections can significantly outlive max_age
Author: multunCreated Sep 22, 2026Updated Sep 23, 2026
This problem was observed in a production system, where a fix is also deployed
Steps to reproduce
max_age: 90reaper_frequency: 10- put the connection pool under high load (80%+ usage)
Expected behavior
After roughly 90s, all connections are recycled.
No connection lives for more than max(max_age + transaction_time, max_age + reaper_frequency)
Actual behavior
The time it takes for all connections to be recycled is:
- a lot higher than max_age
- random
In our production setup, a few connections reach connection_age>=120s for max_age=90s.
This prevents graceful shutdown and transition between connection poolers such as pgbouncer, causing PQconsumeInput() server closed errors
Reproducer
https://github.com/rails/rails/issues/58851#issuecomment-5782156081
System configuration
Rails version: 8.1.3
Ruby version: 4.0.6
Source: rails/rails