# "upstream request timeout" / 504 after about 15 seconds
Services: any backend that makes outbound HTTP calls · Owner: backend lead

## Symptom
The browser gets 504 or the text `upstream request timeout` at roughly 15s. The backend may keep
working for minutes afterwards.

## Confirm it is this
- ECS Service Connect (Envoy) gives an inbound request **15s**
  (`HTTP_X_ENVOY_EXPECTED_RQ_TIMEOUT_MS`). A 504 at about 15s means the PHP worker was still busy.
- CloudWatch `/ecs/<tier>/<service>`: search for `Failed to connect` / `Operation timed out`. curl
  reports the wait, e.g. `after 133118 ms`.
- Usual cause: a curl to an unroutable on-prem host (`192.168.*`) or a slow third party, **with no
  timeout**. try/catch can't bound a blocked socket.

## Fix
Mitigate: if a recent deploy added the call, `ecs-rollback.md`. Otherwise make the dependency
reachable or disable the call. Real fix: set `CURLOPT_CONNECTTIMEOUT` (5s or less) and
`CURLOPT_TIMEOUT` on the handle, and move the base URL to an env-var param.

## Prevent
`python ci/curl-timeout-check.py` gates CI against `ci/curl-timeout-baseline.txt`. Counts may only go
down; never regenerate the baseline to make a build pass.
