DBConnection.ConnectionError - requestes are coming in and your connection pool cannot serve them fast enough


I am running tests, and some of them are returning this error →

     ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 1998ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
       1. Ensuring your database is available and that you can connect to it
       2. Tracking down slow queries and making sure they are running fast enough
       3. Increasing the pool_size (albeit it increases resource consumption)
       4. Allowing requests to wait longer by increasing :queue_target and :queue_interval
     See DBConnection.start_link/2 for more information

I tried increasing pool_size to 20 and queue_target to 5000, however that didn’t do a trick.

I would like to add that when I run tests separately on a file where such issue occurred, it passes with no errors, however when I run all the tests together, the problem occurs.

I am stuck and will be thankful for help!

This may be caused by too much contention on the database. One of the reasons might be that multiple tests are trying to insert the same data into a column with a unique constraint. If this is the case, make sure you make the data unique. For example, append a unique ID to an email address:

uid = System.unique_integer([:positive, :monotonic])

If this is happening on the CI, this might mean that the tests are simply overloading the DB and you need a more powerful machine or slow down the tests with something like mix test --max-cases 1.


Thanks a lot for your reply! I will follow your instructions and see where it gets me :slight_smile: