The connection_expiration extension modifies a database’s connection pool to validate that connections checked out from the pool are not expired, before yielding them for use. If it detects an expired connection, it removes it from the pool and tries the next available connection, creating a new connection if no available connection is unexpired. Example of use:
The default connection timeout is 14400 seconds (4 hours). To override it:
DB.pool.connection_expiration_timeout = 3600 # 1 hour
Note that this extension only affects the default threaded and the sharded threaded connection pool. The single threaded and sharded single threaded connection pools are not affected. As the only reason to use the single threaded pools is for speed, and this extension makes the connection pool slower, there’s not much point in modifying this extension to work with the single threaded pools. The threaded pools work fine even in single threaded code, so if you are currently using a single threaded pool and want to use this extension, switch to using a threaded pool.