Fixing Connection Tiemouts in Rails Worker Processes
If you’ve been having trouble with the following error
could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
in your sidekiq or sneakers worker, there are 2 ways I came accross to mitigate it.
- Your DB pool is probably lesser than the worker threads that are being spawned. Fix this by specifying the pool size to be equal to the number of threads in
- Open and close the connection explicitly as the worker process may not be releasing the connection on its own after it finishes. I’ve seen this happen too many times with sneakers (a rabbitmq adapter)
Hope that helped.