Find the request your server took too long to answer

Cloudflare error 524 means Cloudflare connected to your origin server and sent the request, but no HTTP response came back before its time limit, 125 seconds by default. Your server is up and reachable. Something it does for that particular request, such as a large database query, an export or a report, takes longer than Cloudflare will wait, or the server is too short of resources to answer in time.

How Cloudflare's 524 timeout works

  • After it sends the request, Cloudflare waits for your server's response for the length of its Proxy Read Timeout, 125 seconds by default. A 524 means the server acknowledged the request and then stayed silent for that whole window. Cloudflare also shows a 524 when writing the request to your server doesn't finish within its 30-second Proxy Write Timeout, which can't be adjusted.

  • Only Enterprise customers can raise the read timeout, up to 6,000 seconds, according to Cloudflare's error 524 guide. On other plans, a request that needs more than about two minutes has to get faster, run in the background, or go through a hostname that Cloudflare doesn't proxy.

Time the slow request at the origin

# Send the slow request straight to your origin (203.0.113.10 here) and time the first byte
curl -sS -o /dev/null --max-time 300 --connect-to ::203.0.113.10 https://yoursite.com/reports/export \
  -w "first byte after %{time_starttransfer}s, status %{http_code}\n"

# Repeat it a few times to see whether it's always slow or only some of the time
for i in 1 2 3; do
  curl -sS -o /dev/null --max-time 300 --connect-to ::203.0.113.10 https://yoursite.com/reports/export \
    -w "run $i: %{time_starttransfer}s\n"
done

What keeps the origin from answering in time

  • A long-running process

    Reports, exports, imports and batch jobs that run inside the request can take minutes once the data set grows.

  • An overloaded server

    When CPU, memory or the pool of workers runs short, even quick requests wait their turn, and the slowest ones pass the limit.

  • A slow step the request waits on

    A locked database table or an outside API that hangs holds the whole response until Cloudflare stops waiting.

Cloudflare's error 524 guide names a long-running process and an overloaded origin as the common causes, suggests status polling for large HTTP processes, and recommends logging each request's response time, pointing to the log format docs for Apache and nginx.

How to fix Cloudflare error 524

  1. Log how long each request takesAdd the response time to your web server's access log, so the requests that run close to two minutes stand out along with their URLs.
  2. Return right away and poll for the resultStart the long job, answer at once with a job ID, and have the page check a status URL every few seconds until the result is ready.
  3. Profile where the minutes goTrace one slow request from start to finish. When one query or one outside call takes most of the time, an index, a cache or a tighter timeout on that call can bring the response under the limit.
  4. Give long exports their own hostnameFor an export that regularly takes more than 125 seconds to finish, serve it from a hostname that doesn't pass through Cloudflare's proxy, as Cloudflare's guide suggests.

Frequently asked questions

What's the difference between a 524 and a 504?

Both mean a proxy waited too long for your server. A 524 is Cloudflare's own code for its wait on your origin, 125 seconds by default according to Cloudflare's guide. A 504 usually comes from a gateway or proxy in your own setup, such as a load balancer with its own limit, and Cloudflare passes it on in a Cloudflare-branded page. Cloudflare's 502 and 504 guide says an unbranded 504 came from Cloudflare itself. The 504 Gateway Timeout guide linked below covers the first case.

Why do I get a 524 when my server finishes the work?

Because Cloudflare stopped waiting, not your server. The job can keep running and finish, but the visitor already has the error page, and if they retry, the same job can start twice. Make long jobs safe to run twice, or check for one already running before starting another.