Tech

Explainer

Updated

What does the HTTP 504 status code mean?

Key facts

A cache can send a 504 too: RFC 9111 says a disconnected cache that cannot revalidate a stale response marked must-revalidate should generate a 504 unless another error code is more applicable.

The HTTP 504 (Gateway Timeout) status code means that a server acting as a gateway or proxy did not receive a timely response from an upstream server it needed to reach to complete the request, according to RFC 9110, the IETF standard that defines HTTP semantics. In the words of Section 15.6.5 of RFC 9110, "The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request."

Who sends a 504

Section 3.7 of RFC 9110 names three common forms of HTTP intermediary: proxy, gateway and tunnel. A proxy is a forwarding agent the client chooses, usually through local configuration rules. A gateway, also called a reverse proxy, acts as an origin server toward the client but forwards requests inbound to another server or servers, and the same section says gateways are often used for "accelerator" caching and to spread HTTP services across multiple machines for load balancing.

How 504 compares with nearby codes

RFC 9110 puts 504 in the 5xx (Server Error) class, which means the server is aware that it has erred or is incapable of performing the requested method. Nearby codes differ in who failed and how.

CodeNameWhat RFC 9110 says it means
504Gateway TimeoutA gateway or proxy did not receive a timely response from an upstream server
502Bad GatewayA gateway or proxy received an invalid response from an inbound server
503Service UnavailableThe server cannot handle the request now because of a temporary overload or scheduled maintenance
500Internal Server ErrorAn unexpected condition prevented the server from fulfilling the request
408Request TimeoutThe server did not receive a complete request message within the time it was prepared to wait

The meanings are summarized from Sections 15.6.5, 15.6.3, 15.6.4, 15.6.1 and 15.5.9 of RFC 9110. The two timeouts point in opposite directions: a 504 means the gateway gave up waiting on the server behind it, while a 408 means the server gave up waiting on the client's own request, which puts 408 in the 4xx client error class. A 502 means an answer came back but was invalid, and a 504 means no answer came back in time. The site also explains 500 Internal Server Error.

When a cache sends a 504

A 504 does not always mean a slow server. RFC 9111, the HTTP caching standard, tells caches to use the same code in two cases where they cannot reach the origin or are told not to.

DirectiveSet byWhat RFC 9111 says the cache does
must-revalidateThe server, on a responseIf disconnected, it must send an error rather than reuse the stale response, and that error should be 504 unless another code is more applicable
only-if-cachedThe client, on a requestA cache that honors it should answer with a stored response that fits the request, or with 504

The first row is from Section 5.2.2.2 of RFC 9111, which says servers ought to use must-revalidate if and only if failure to validate a request could cause incorrect operation, such as a silently unexecuted financial transaction. The second row is from Section 5.2.1.7, where the client is asking only for a stored response.

Can a client retry after a 504?

Section 9.2.2 of RFC 9110 sets the general retry rules. PUT, DELETE and the safe methods such as GET are idempotent, meaning several identical requests have the same intended effect as one, so they can be repeated automatically after a communication failure. A client should not automatically retry a non-idempotent method such as POST unless it has a way to know the request is idempotent or that the original was never applied, a proxy must not automatically retry non-idempotent requests, and a client should not automatically retry a failed automatic retry.

What a server should send with a 504

For every 5xx code, RFC 9110 says that, except when responding to a HEAD request, the server should send a representation explaining the error situation and whether it is a temporary or permanent condition, and that a user agent should display that representation to the user. A 504 is also not heuristically cacheable: the overview of status codes gives the heuristically cacheable codes in RFC 9110, by way of example, as 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414 and 501, and says all other status codes are not.

What changed and when

StandardPublishedWhere 504 is defined
RFC 2616June 1999Section 10.5.5
RFC 7231June 2014Section 6.6.5
RFC 9110June 2022Section 15.6.5

RFC 2616, published in June 1999, defined 504 as a timeout from the upstream server named by the URI, giving HTTP, FTP and LDAP as examples, or from some other auxiliary server such as DNS, and added a note to implementors that some deployed proxies were known to return 400 or 500 when DNS lookups timed out. RFC 7231, published in June 2014, obsoleted RFC 2616 and shortened the definition to the sentence used today, dropping the list of protocols, the DNS example and the note. RFC 9110 was published in June 2022 on the Standards Track as STD 97 and obsoletes RFC 7231, as its header shows; the 504 definition moved to Section 15.6.5 with its wording unchanged. The IANA registry now points code 504 to RFC 9110, Section 15.6.5, and shows its last update as September 15, 2025.

Have another question?