Reputation: 26690
The Rails 4 app had been working for 5 months flawlessly, but some minutes ago it started to encounter an error:
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds))
The DBMS is a locally installed MySQL.
It did not matter how many times I tried to reload pages or refer to different URLs of an application.
The problem was gone only after I restarted the Rails app.
What was it and how to make the app to solve this issue automatically without admin's intervention?
Upvotes: 0
Views: 622
Reputation: 7366
This is something that you have in your database.yml
{environment_name}:
adapter: mysql2
encoding: utf8
database: {product_name}_environment_name
username: username
password: password
socket: /var/run/mysqld/mysqld.sock
Add correct values for 'reaping_frequency' and 'pool' in connection parameter and it might look like
{environment_name}:
adapter: mysql2
encoding: utf8
database: {product_name}_environment_name
pool: 15
reaping_frequency: 3
username: username
password: password
socket: /var/run/mysqld/mysqld.sock
Options descriptions
pool: number indicating size of connection pool (default 5)
checkout_timeout: number of seconds to block and wait for a connection before giving up and raising a timeout error (default 5 seconds).
reaping_frequency: frequency in seconds to periodically run the Reaper, which attempts to find and close dead connections, which can occur if a programmer forgets to close a connection at the end of a thread or a thread dies unexpectedly. (Default nil, which means don't run the Reaper).
dead_connection_timeout: number of seconds from last checkout after which the Reaper will consider a connection reapable. (default 5 seconds).
Upvotes: 1