Skip to content

Kong 502, 503, 504: name resolution failed, invalid response, timing out

Networkingtested on Kong OSS 3.9.4 (Docker, DB-less), decK v1.69.0

502, 503 and 504 all come from Kong, but for different reasons. The message in the body and the error log with the request_id tell you which one it is.

Symptom

{  "message":"An invalid response was received from the upstream server",  … } 502
{  "message":"name resolution failed",  … } 503
{  "message":"The upstream server is timing out",  … } 504

Three deliberately broken services: wrong port, unknown name, backend too slow.

Diagnosis

The details are in Kong's log.

docker compose logs kong 2>&1 | grep '\[error\]' | tail -3 | cut -c1-120
kong-1  | … [error] … connect() failed (111: Connection refused) while connecting to u…
kong-1  | … [error] … DNS resolution failed: dns server error: 3 name error. Tried: …
kong-1  | … [error] … upstream timed out (110: Connection timed out) while reading res…

Causes

502Backend unreachable

Nothing listens on the port (connection refused) – or the backend answers with garbage.

503Name not resolvable

The hostname in the service does not exist (dns server error: 3 name error). 503 also appears when an upstream has no healthy target.

504Too slow

The backend does not answer within read_timeout (here 1000 ms against a 3 s delay).

Fix

Depending on the code: correct the port in the service, check the hostname, adapt read_timeout to the real response time – then reload the configuration.
kreload
Kong reloaded

Don't: Turning up retries to hide 504s – a slow backend only gets more load.

▶
Break it yourself and find it – free
Kong hands-on, Day 2: services and routes, strip_path, methods, hosts and reading error codes.
Go to day 2 →

FAQ

How do I tell a 503 from Kong from a 503 of the backend?

If it comes from Kong, the body carries the message in Kong's format and the header has X-Kong-Response-Latency.

What does retries: 0 in the example mean?

Kong does not retry the request. That way the test shows the pure timeout without retries stretching it.

Related error patterns

More