Skip to content
Latchkey

Dredd "connect ECONNREFUSED" against the API in CI

Dredd validated your API description against a live server, but the server was not accepting connections at the endpoint you passed. In CI the server is usually starting in the same job and Dredd runs before its port is open.

What this error means

Dredd fails every transaction with "Error connecting to server under test!" and "connect ECONNREFUSED 127.0.0.1:3000", exiting non-zero.

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

Common causes

The server was not ready when Dredd started

Dredd runs before the API binds its port, so the connection is refused for every transaction.

Wrong endpoint host or port

The endpoint argument points at a host or port the app does not listen on in CI.

How to fix it

Let Dredd start and wait for the server

  1. Use Dredd's server and wait options so it launches the app and waits.
  2. Or poll a health endpoint before invoking Dredd.
  3. Confirm the endpoint matches the app host and port.
Terminal
dredd apiary.apib http://127.0.0.1:3000 \
  --server "npm start" --server-wait 15

Poll readiness in the workflow

Start the server, wait for a health endpoint, then run Dredd so it never connects too early.

Terminal
until curl -sf http://127.0.0.1:3000/health; do sleep 2; done
dredd apiary.apib http://127.0.0.1:3000

How to prevent it

  • Use --server and --server-wait or a health poll before Dredd runs.
  • Match the endpoint to the app host and port exactly.
  • Gate the job on service readiness.

Frequently asked questions

What causes ""connect ECONNREFUSED" (Dredd)"?
Dredd runs before the API binds its port, so the connection is refused for every transaction.
How do I fix "connect ECONNREFUSED" (Dredd)?
Let Dredd start and wait for the server

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card