Elixir "** (DBConnection.ConnectionError)" in CI
DBConnection manages Ecto's connection pool. A ConnectionError means it could not hand out a working connection: the checkout timed out, the socket closed, or the database stopped accepting connections mid-run.
What this error means
Tests fail intermittently or in bulk with "** (DBConnection.ConnectionError)" mentioning "connection not available", "client timed out", or "tcp recv: closed".
** (DBConnection.ConnectionError) connection not available and request was dropped
from queue after 2950ms. This means requests are coming in and your connection
pool cannot serve them fast enoughCommon causes
Pool exhausted or checkout timeout
More concurrent DB work than pool_size, or slow queries, empties the pool so requests time out waiting for a connection.
The database dropped connections
A restarting service container, an OOM-killed Postgres, or a network blip closes sockets, surfacing as "closed" ConnectionErrors.
How to fix it
Right-size the pool and timeouts for tests
- Set a pool_size that matches test concurrency for the test repo.
- Raise ownership/queue timeouts if checkouts are legitimately slow.
- Re-run and confirm connections are served.
config :my_app, MyApp.Repo,
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: System.schedulers_online() * 2,
ownership_timeout: 60_000Stabilize the database service
Ensure the Postgres service is health-checked and adequately resourced so it does not restart under load.
options: >-
--health-cmd pg_isready --health-interval 5s
--health-timeout 5s --health-retries 10How to prevent it
- Tune pool_size to test concurrency and query cost.
- Health-check and resource the DB service so it stays up.
- Use the Ecto SQL Sandbox for isolated, connection-scoped tests.