# ECONNREFUSED in CI

Classification: environment
Frameworks: CI, Playwright, Jest
Canonical: https://automationtester.in/failures/econnrefused-in-ci

## Recognizable error

```text
Error: connect ECONNREFUSED 127.0.0.1:5432
```

## What it means

The test process reached the target host, but no service was accepting connections on the requested port.

## Ranked causes, checks, and fixes

### 1. The dependency never became ready

A database, API, or web server started slowly or crashed during boot.

Diagnostic: Read the dependency logs and probe its health endpoint before running tests.

Fix: Gate the suite on a bounded health check and fail with the dependency logs.

### 2. localhost points at the wrong container

Inside a container, 127.0.0.1 refers to that container rather than another service.

Diagnostic: Print the resolved base URL and compare it with the CI service name and network.

Fix: Use the CI service hostname or expose the correct host gateway.

### 3. The configured port differs from the listening port

Environment variables and container mappings can disagree.

Diagnostic: Compare the application listen address, health check, and test base URL.

Fix: Use one validated configuration value and publish the correct container port.

## Prevention

- Use explicit health checks.
- Validate base URLs at suite startup.
- Attach service logs on failure.

## Primary references

- [Node.js common system errors](https://nodejs.org/api/errors.html#common-system-errors)

Triage this failure locally: https://automationtester.in/tools/test-failure-triage