🔶

Cloudflare Error

Cloudflare Error 524: A Timeout Occurred

Cloudflare connected to origin, but origin failed to return an HTTP response within 100 seconds.

What This Error Means

A 524 indicates that Cloudflare successfully established a TCP connection with your origin server, but the origin took longer than Cloudflare’s 100-second edge timeout to finish executing and send an HTTP response.

Why It Occurs

Heavy unoptimized database queries, long synchronous file processing, background script execution blocking web requests, or deadlocked application worker processes.

Symptoms

  • ⚠ HTTP 524 displayed after exactly 100 seconds of browser loading spinner
  • ⚠ Origin server CPU or database load spikes during requests
  • ⚠ Occurs predominantly on complex report generation, export, or large upload routes

Common Causes

  • • Synchronous long-running background task executed directly inside the HTTP request cycle
  • • Database query scanning millions of unindexed rows or locked tables
  • • Upstream service deadlocked or blocked waiting on third-party API

How to Fix It

  1. Move long-running tasks to an asynchronous background worker queue (e.g. BullMQ, Celery, Redis)
  2. Optimize database queries with proper indexes and EXPLAIN ANALYZE
  3. Enable HTTP streaming (chunked transfer encoding) to keep the connection active while data streams
  4. For Enterprise Cloudflare accounts, request a custom proxy timeout increase
CommandPurpose
top -b -n 1Check system CPU and load average on origin
mysqladmin processlistCheck for slow running database queries

Verification

  • ✓ Run query directly on database and confirm execution completes in under 5 seconds
  • ✓ Verify Cloudflare Analytics shows 524 error count drops to zero

Prevention

  • → Never execute synchronous operations longer than 30 seconds inside an HTTP request handler

Related