Skip to content
Latchkey

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.

Pact
Verifying a pact between web-consumer and orders-provider
  Get failed: Connection refused (Connection refused)
  connecting to http://localhost:8080

Common 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

  1. Boot the provider (or its container) as a prior step.
  2. Wait until the health endpoint responds before running verify.
  3. Point providerBaseUrl at the exact host and port it bound to.
.github/workflows/ci.yml
# start provider, then wait for it to be ready
npm run start:provider &
npx wait-on http://localhost:8080/health
npm run test:pact:verify

Align the port everywhere

Use one environment variable for the provider port and reference it in both the app and the verifier config.

.github/workflows/ci.yml
env:
  PORT: '8080'
# providerBaseUrl: http://localhost:8080

How 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.

Frequently asked questions

What causes "Provider "Connection refused" on verify"?
The verification step runs before, or without, a step that boots the provider, so nothing is listening on the target port.
How do I fix Provider "Connection refused" on verify?
Start and wait for the provider before verifying

Related guides

References

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