Last Update: 2023-06-12 13:05:49 -0700

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 does not work with the single threaded and sharded single threaded connection pools. 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 non-single 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 another pool.

Related module: Sequel::ConnectionExpiration