Server error · 504
504 Gateway Timeout
A 504 Gateway Timeout means a proxy or load balancer reached the origin and did not receive a finished HTTP response before its own timer expired. The gateway is up. The upstream was too slow or stuck.
HTTP status codes explained · the longer reference on the blog.
What 504 means
The proxy opened a connection, sent the request, and waited. The status is the proxy’s decision to stop waiting. The origin may still be working on the request and may even finish after the visitor has already seen the 504. That is why logs sometimes show a slow 200 on the app after the edge has already returned 504.
A 502 Bad Gateway means the reply was invalid or the connection broke. A 408 Request Timeout means the server was waiting for the client to finish sending. Cloudflare’s 524 is the same idea as 504, with Cloudflare as the gateway that gave up. The homepage checker waits 10 seconds. A monitor waits up to 60 seconds. If your edge cuts off first, the checker records HTTP 504. If the edge waits longer than our check, the checker records a timeout and no status code.
Common causes
The origin is stuck on a slow dependency
A database query without a timeout, a lock, a DNS lookup, or an outbound HTTP call that never returns. The web worker stays busy, and the proxy’s timer fires.
The proxy timer is shorter than real work
A report or upload that legitimately takes 40 seconds behind a proxy that allows 30. Users hit 504 even though the job would have finished.
Workers are all busy
New requests queue until the gateway times out. The app’s own logs show queue time, and a few requests that do get a worker return 200 slowly.
The upstream IP is black-holed
The proxy can route toward the origin, and packets are dropped. The connection attempt hangs until the timer. A refused port fails faster and is usually a 502.
How to fix it
Find the request in origin logs
Match the timestamp. If the origin has no record, the request never arrived and you are debugging the network path. If it has a slow trace, the timer and the work disagree.
Put timeouts on downstream calls
Database statements, HTTP clients, and locks need their own limits that finish before the proxy timer. A 504 is often a missing timeout one layer down.
Move long work off the request
A page that waits for a report, a video transcode, or a third-party API should enqueue that work and return. Raising the proxy timeout without a cap ties up workers.
Align the timers on purpose
Write down the browser, CDN, proxy, and app timeouts. Each inner timer should be shorter than the one outside it, so the error you see names the layer that is slow.
Is it your site, or just you?
Ask someone off your network to open the same URL, or use a phone on cellular data. A 504 for every caller is the origin or the gateway timer. A 504 only on one slow network can be that path.
The homepage checker is outside your browser and waits 10 seconds. If it reports HTTP 504, the gateway is giving up on requests from our network too. If it reports 200 with a high response time, your gateway allows longer than 10 seconds and some visitors may still be close to the limit.
How to monitor for 504
Expect 200. A monitor waits up to 60 seconds for an answer. A 504 from the origin fails the check and alerts after a second consecutive failure. A silent origin that exceeds the monitor timeout fails too, with a timeout message and no status code. Either way you get an alert. The status in the alert tells you which one happened.
The checker on the ismysiteup homepage requests the URL from our servers and shows the HTTP status, response time, and SSL details. No account is required, and that checker allows 5 checks per hour from the same network. A free account watches 5 URLs, each checked every 10 minutes, and sends alerts on WhatsApp, Telegram, Slack, or email. A monitor expects HTTP 200 unless you set a different expected status (100–599). One failed check is confirmed with a second check before the first alert, and a later success sends a recovery alert. Pro (every 5 minutes) and Business (every minute) are listed on the pricing page; paid checkout is not open yet.
Related status codes
- 502Bad GatewayA proxy received an invalid response from the server behind it.
- 503Service UnavailableThe server is reachable and is refusing new work for the moment.
- 522Connection Timed OutCloudflare tried to open TCP to the origin and the handshake never finished.
- 524A Timeout OccurredCloudflare connected and the origin did not finish a response in time.
- 408Request TimeoutThe server waited for the client to finish sending, then gave up.
FAQ
What does 504 Gateway Timeout mean?
A proxy did not get a complete response from the upstream server before the proxy’s timer ended. The upstream may still have been working.
How is 504 different from 502?
504 is a wait that expired. 502 is a response the proxy could not accept as HTTP, or a connection that failed before a response.
Why do I see 504 when the app log shows success?
The app finished after the proxy had already returned 504 to the visitor. Shorten the work or raise the proxy timer so the visitor is still connected when the app responds.