Skip to content
Latchkey

Dredd "Error: connect ECONNREFUSED" to the API in CI

Dredd tried to connect to the API endpoint you passed and the host refused the connection, so nothing is listening there yet. In CI this means Dredd ran before the API was up, or the URL is wrong.

What this error means

Dredd errors every transaction with "Error: connect ECONNREFUSED 127.0.0.1:3000" and reports the API as unreachable.

dredd
error: Error connecting to server under test!
Error: connect ECONNREFUSED 127.0.0.1:3000

Common causes

The API was not started or is still booting

Dredd ran before the service began listening, so the connection is refused for every transaction.

The endpoint URL host or port is wrong

The URL passed to Dredd targets a port the app does not bind, or the wrong host for a service container.

How to fix it

Start and wait for the API before Dredd

  1. Start the API in the background (or as a service container).
  2. Poll its health endpoint until it responds.
  3. Run Dredd against the confirmed-ready URL.
.github/workflows/ci.yml
- run: npm start &
- run: |
    for i in $(seq 1 30); do curl -sf http://localhost:3000/health && break; sleep 2; done
- run: dredd apiary.apib http://localhost:3000

Let Dredd start the server for you

Use the --server option so Dredd launches the app and waits before testing.

Terminal
dredd apiary.apib http://localhost:3000 \
  --server "npm start" --server-wait 10

How to prevent it

  • Gate Dredd on a readiness check, or use --server with a wait.
  • Confirm the endpoint host and port match how the API is exposed.
  • Fail the wait step clearly if the API never comes up.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →