Pact provider not running on expected port during verification in CI
Provider verification replays interactions against a live provider URL. If the app is not booted or is on a different port than providerBaseUrl, the verifier cannot connect and every interaction fails with a connection error.
What this error means
Verification fails immediately with "Connection refused" or "ECONNREFUSED" against the provider base URL, and no interaction is actually replayed.
Verifying a pact between web-consumer and orders-provider
Get failed: Connection refused (Connection refused)
connecting to http://localhost:8080Common causes
The provider app was never started in the job
The verification step runs before, or without, a step that boots the provider, so nothing is listening on the target port.
A port mismatch between app and providerBaseUrl
The provider binds to one port while providerBaseUrl targets another, so the connection is refused.
How to fix it
Start and wait for the provider before verifying
- Boot the provider (or its container) as a prior step.
- Wait until the health endpoint responds before running verify.
- Point
providerBaseUrlat the exact host and port it bound to.
# start provider, then wait for it to be ready
npm run start:provider &
npx wait-on http://localhost:8080/health
npm run test:pact:verifyAlign the port everywhere
Use one environment variable for the provider port and reference it in both the app and the verifier config.
env:
PORT: '8080'
# providerBaseUrl: http://localhost:8080How to prevent it
- Health-check the provider before verification, never assume it is up.
- Drive the provider port from a single environment variable.
- Fail fast if the health endpoint does not respond in time.