Cloudflare Error 524 means Cloudflare connected to your origin server, but the server didnβt respond with an HTTP response within 100 seconds.
Why this happens
Cloudflare acts as a reverse proxy between users and your origin server. It enforces a 100-second timeout on the connection to your origin (non-Enterprise plans). If your server takes longer than that to generate a response β whether due to a slow database query, heavy computation, or an overloaded process β Cloudflare drops the connection and shows a 524 error to the user.
What causes this error
- Slow origin server β your app takes too long to process the request
- Long-running process β file uploads, report generation, database migrations
- Origin server overloaded β too many requests, not enough resources
Fix 1: Optimize the slow endpoint
Check which endpoint is timing out and optimize it:
- Add database indexes for slow queries
- Move heavy processing to background jobs
- Cache expensive computations
Fix 2: Increase Cloudflare timeout (Enterprise only)
Enterprise plans can increase the proxy read timeout up to 600 seconds. Free/Pro/Business plans are fixed at 100 seconds.
Fix 3: Use background processing
For long-running tasks, return a 202 Accepted immediately and process in the background:
app.post("/generate-report", (req, res) => {
const jobId = startBackgroundJob(req.body);
res.status(202).json({ jobId, status: "processing" });
});
app.get("/job/:id", (req, res) => {
const status = getJobStatus(req.params.id);
res.json(status);
});
Fix 4: Bypass Cloudflare for long requests
Use a subdomain thatβs not proxied through Cloudflare (grey cloud in DNS settings) for endpoints that legitimately take over 100 seconds.
Alternative solutions
Use WebSockets or Server-Sent Events (SSE) for long-running operations β Cloudflare has a separate, longer timeout for WebSocket connections. You can also use Cloudflare Workers to stream partial responses back to the client, keeping the connection alive while your origin processes the request.
Prevention
- Set up monitoring and alerts for endpoint response times so you catch slow endpoints before they hit the 100-second limit.
- Design APIs so that any operation expected to take more than a few seconds uses an async job pattern (submit β poll β retrieve) instead of blocking the HTTP response.
Related: Nginx: 504 Gateway Timeout fix Β· Vercel Serverless Timeout fix Β· Cloudflare Workers vs Vercel Edge