HTTP

Status Code

524 A Timeout Occurred

Cloudflare-specific error when the origin server takes too long to respond. Learn how to diagnose and fix 524 timeout errors.

9 min read intermediate Try in Playground

TL;DR: Origin server took longer than 100 seconds to respond to Cloudflare. Optimize slow database queries, implement background jobs, or add caching.

What is 524 A Timeout Occurred?

A 524 A Timeout Occurred is a Cloudflare-specific status code that indicates the origin server successfully established a connection with Cloudflare but failed to send a complete HTTP response within the configured timeout period (typically 100 seconds). Think of it like calling a restaurant to place an order—they answer the phone but take so long to respond that you eventually hang up.

This differs from a 522 error (connection timeout) because the connection was established successfully, but the server is taking too long to generate and send the response.

When Does This Happen?

You’ll see a 524 timeout error in these common situations:

1. Slow Database Queries

Request requires complex database query
→ Query takes 120 seconds to complete
→ Exceeds 100-second Cloudflare timeout
→ Returns 524

2. Heavy Processing Tasks

Large file generation or processing
→ Server working but taking too long
→ Response not ready within timeout
→ 524 error

3. External API Dependencies

Application calls slow third-party API
→ Waiting for external service response
→ Total time exceeds Cloudflare timeout
→ Returns 524

4. Large File Uploads/Processing

User uploads large file
→ Server processing takes 150 seconds
→ Exceeds timeout threshold
→ 524 timeout

5. Resource Exhaustion

Server under heavy load
→ Requests queued and processed slowly
→ Response time exceeds 100 seconds
→ 524 error

Example Responses

Basic 524 Response:

HTTP/1.1 524 A Timeout Occurred
Server: cloudflare
Date: Sat, 18 Jan 2026 10:00:00 GMT
Content-Type: text/html
CF-RAY: 7d1234567890abcd-LAX

<!DOCTYPE html>
<html>
<head>
  <title>524: A timeout occurred</title>
</head>
<body>
  <h1>The origin web server timed out responding to this request</h1>
  <p>Ray ID: 7d1234567890abcd</p>
</body>
</html>
```javascript

**Detailed Cloudflare Error Page:**

```http
HTTP/1.1 524 A Timeout Occurred
Server: cloudflare
CF-RAY: 7d1234567890abcd-SJC
CF-Cache-Status: DYNAMIC
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Error 524 - A timeout occurred</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      max-width: 900px;
      margin: 50px auto;
      padding: 20px;
      line-height: 1.6;
      color: #333;
    }
    .error-code {
      font-size: 80px;
      color: #e74c3c;
      font-weight: bold;
      margin: 20px 0;
    }
    .warning {
      background: #fff3cd;
      border-left: 4px solid #ffc107;
      padding: 20px;
      margin: 20px 0;
    }
    .info {
      background: #d1ecf1;
      border-left: 4px solid #17a2b8;
      padding: 20px;
      margin: 20px 0;
    }
    .ray-id {
      background: #343a40;
      color: #fff;
      padding: 15px;
      font-family: 'Courier New', monospace;
      margin: 20px 0;
      border-radius: 3px;
    }
    code {
      background: #e9ecef;
      padding: 2px 6px;
      border-radius: 3px;
      font-family: 'Courier New', monospace;
      font-size: 0.9em;
    }
  </style>
</head>
<body>
  <div class="error-code">524</div>
  <h1>A timeout occurred</h1>

  <p>The origin server successfully connected to Cloudflare but did not send an HTTP
  response before the connection timed out. Cloudflare waited 100 seconds for a response
  but did not receive one.</p>

  <div class="warning">
    <h2>⏱️ What happened?</h2>
    <p><strong>Cloudflare successfully established a connection</strong> with your origin
    server, meaning:</p>
    <ul>
      <li>✓ Your server is online and reachable</li>
      <li>✓ The TCP connection was established</li>
      <li>✓ Your server received the HTTP request</li>
    </ul>
    <p>However, your server took longer than <strong>100 seconds</strong> to generate
    and send a complete response, so Cloudflare terminated the connection.</p>
  </div>

  <div class="info">
    <h2>Common Causes:</h2>
    <ol>
      <li>
        <strong>Slow database queries</strong>
        <ul>
          <li>Complex SQL queries taking too long to execute</li>
          <li>Missing database indexes causing full table scans</li>
          <li>Database server overloaded or slow</li>
        </ul>
      </li>
      <li>
        <strong>Heavy server-side processing</strong>
        <ul>
          <li>Large file generation (PDFs, exports, reports)</li>
          <li>Image/video processing taking too long</li>
          <li>Complex calculations or algorithms</li>
        </ul>
      </li>
      <li>
        <strong>External API dependencies</strong>
        <ul>
          <li>Waiting for slow third-party API responses</li>
          <li>Multiple sequential API calls adding up</li>
          <li>API rate limiting causing delays</li>
        </ul>
      </li>
      <li>
        <strong>Server resource exhaustion</strong>
        <ul>
          <li>CPU at 100% causing slow processing</li>
          <li>Memory exhausted, causing swapping</li>
          <li>Too many concurrent requests</li>
        </ul>
      </li>
      <li>
        <strong>Application performance issues</strong>
        <ul>
          <li>Inefficient code or algorithms</li>
          <li>Memory leaks slowing down processing</li>
          <li>Blocking operations in request handlers</li>
        </ul>
      </li>
    </ol>
  </div>

  <div class="info">
    <h2>What can I do?</h2>

    <p><strong>If you're a visitor:</strong></p>
    <ul>
      <li>Wait a moment and try again</li>
      <li>The server may be under heavy load temporarily</li>
      <li>Contact the website owner if the issue persists</li>
    </ul>

    <p><strong>If you're the website owner:</strong></p>
    <ol>
      <li>
        <strong>Check server performance:</strong>
        <ul>
          <li>Monitor CPU, memory, and disk usage</li>
          <li>Review server logs for slow requests</li>
          <li>Identify which requests are taking longest</li>
        </ul>
      </li>
      <li>
        <strong>Optimize database queries:</strong>
        <ul>
          <li>Add indexes to frequently queried columns</li>
          <li>Optimize slow queries (use EXPLAIN in SQL)</li>
          <li>Implement query caching</li>
        </ul>
      </li>
      <li>
        <strong>Implement async processing:</strong>
        <ul>
          <li>Move long tasks to background jobs</li>
          <li>Use job queues (Redis, RabbitMQ, etc.)</li>
          <li>Return immediately, process asynchronously</li>
        </ul>
      </li>
      <li>
        <strong>Add caching:</strong>
        <ul>
          <li>Cache expensive computations</li>
          <li>Use CDN caching for static content</li>
          <li>Implement application-level caching</li>
        </ul>
      </li>
      <li>
        <strong>Scale resources:</strong>
        <ul>
          <li>Upgrade server CPU/RAM if needed</li>
          <li>Add more application servers</li>
          <li>Use load balancing</li>
        </ul>
      </li>
      <li>
        <strong>Increase Cloudflare timeout (Enterprise only):</strong>
        <ul>
          <li>Contact Cloudflare to increase timeout limit</li>
          <li>Note: Only available for Enterprise plans</li>
          <li>Better to optimize than increase timeout</li>
        </ul>
      </li>
    </ol>
  </div>

  <div class="warning">
    <h2>🔍 Debugging Tips:</h2>
    <ul>
      <li>Check server logs at timestamp: <code>2026-01-18 10:00:00 UTC</code></li>
      <li>Look for Ray ID: <code>7d1234567890abcd</code> in your logs</li>
      <li>Monitor application performance metrics</li>
      <li>Use APM tools (New Relic, DataDog, etc.) to identify slow endpoints</li>
      <li>Enable slow query logs in your database</li>
    </ul>
  </div>

  <div class="ray-id">
    Cloudflare Ray ID: 7d1234567890abcd<br>
    Your IP: 203.0.113.42<br>
    Timestamp: 2026-01-18 10:00:00 UTC<br>
    Data Center: LAX (Los Angeles)<br>
    Timeout: 100 seconds
  </div>

  <div>
    <a href="https://www.cloudflare.com/5xx-error-landing">Learn more about Cloudflare errors</a> |
    <a href="https://community.cloudflare.com">Cloudflare Community</a>
  </div>
</body>
</html>

Real-World Example

Imagine an analytics dashboard that generates a complex report:

Client Request:

GET /api/reports/annual?year=2025&detailed=true HTTP/1.1
Host: analytics.example.com
User-Agent: Mozilla/5.0...
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
```text

**Server Processing Timeline:**

```json
[10:00:00.000] Cloudflare forwards request to origin
[10:00:00.050] Origin receives request
[10:00:00.100] Query database for 2025 transactions (10M records)
[10:00:45.000] Database query completes (45 seconds)
[10:00:45.100] Process data aggregations
[10:01:20.000] Generate charts and graphs (35 seconds)
[10:01:20.100] Compile into PDF report
[10:01:50.000] PDF generation complete (30 seconds)
[10:01:50.100] Start sending response to Cloudflare
[10:01:50.200] ⏱️ Cloudflare timeout - 100 seconds exceeded!
              Connection terminated before response sent
```text

**Cloudflare Returns 524:**

```http
HTTP/1.1 524 A Timeout Occurred
Server: cloudflare
Date: Sat, 18 Jan 2026 10:01:50 GMT
Content-Type: text/html; charset=UTF-8
CF-RAY: 7d1234567890abcd-LAX

<!DOCTYPE html>
<html>
<head><title>524: Request Timeout</title></head>
<body>
  <h1>Error 524: Request Processing Timeout</h1>

  <p>Your request was received and is being processed, but took longer than the
  100-second timeout limit.</p>

  <div class="timeline">
    <h2>⏱️ Processing Timeline</h2>
    <ul>
      <li><strong>0s:</strong> Request received by origin server</li>
      <li><strong>0-45s:</strong> Database query execution</li>
      <li><strong>45-80s:</strong> Data processing and aggregation</li>
      <li><strong>80-110s:</strong> PDF report generation</li>
      <li><strong>100s:</strong> ⚠️ Cloudflare timeout - connection closed</li>
    </ul>
    <p><strong>Total processing time:</strong> ~110 seconds (exceeded 100s limit)</p>
  </div>

  <div class="solution">
    <h2>Recommended Solution</h2>
    <p>For long-running reports like this, we recommend using asynchronous processing:</p>
    <ol>
      <li>Submit report request → Receive immediate "processing" response</li>
      <li>Server generates report in background</li>
      <li>Poll status endpoint or receive email when complete</li>
      <li>Download completed report</li>
    </ol>
  </div>

  <div class="technical">
    <h2>Technical Details</h2>
    <ul>
      <li><strong>Ray ID:</strong> 7d1234567890abcd</li>
      <li><strong>Timeout:</strong> 100 seconds</li>
      <li><strong>Timestamp:</strong> 2026-01-18 10:01:50 UTC</li>
      <li><strong>Endpoint:</strong> GET /api/reports/annual</li>
    </ul>
  </div>
</body>
</html>

524 vs Other Timeout Errors

CodeIssueConnectionRequest ReceivedProcessingTypical Cause
524Response timeoutEstablishedYesToo slowSlow processing
522Connection timeoutFailedNoN/ACan’t connect
504Gateway timeoutEstablishedYesToo slowStandard timeout
408Request timeoutEstablishedPartialN/AClient too slow

Important Characteristics

Connection Succeeded:

✓ TCP connection established
✓ Request received by origin
✓ Server is processing
✗ Response took too long (>100s)

Default Timeout:

Free/Pro/Business: 100 seconds (not configurable)
Enterprise: Can be increased (contact Cloudflare)

Processing Continues:

Cloudflare closes connection after 100s
Origin server may still be processing
Database queries may still be running
→ Can cause wasted resources

Different from 522:

522: Can't establish connection (15s)
524: Connection OK, but response slow (100s)

Performance Optimization Strategies

1. Implement Background Jobs:

// Express.js with Redis queue
const Queue = require('bull')
const reportQueue = new Queue('reports')

// API endpoint - return immediately
app.get('/api/reports/annual', async (req, res) => {
  const jobId = generateId()

  // Add job to queue
  await reportQueue.add({
    jobId,
    userId: req.user.id,
    year: req.query.year
  })

  // Return immediately (< 1 second)
  res.json({
    status: 'processing',
    jobId,
    statusUrl: `/api/reports/status/${jobId}`
  })
})

// Process in background (can take 200+ seconds)
reportQueue.process(async (job) => {
  const data = await generateAnnualReport(job.data)
  await saveReport(job.data.jobId, data)
  await notifyUser(job.data.userId, job.data.jobId)
})

// Status check endpoint
app.get('/api/reports/status/:jobId', async (req, res) => {
  const report = await getReport(req.params.jobId)

  if (!report) {
    return res.json({ status: 'processing' })
  }

  res.json({
    status: 'complete',
    downloadUrl: `/api/reports/download/${req.params.jobId}`
  })
})
```text

**2. Add Database Indexes:**

```sql
-- Before: Slow query (120 seconds)
SELECT user_id, SUM(amount) as total
FROM transactions
WHERE created_at >= '2025-01-01'
  AND created_at < '2026-01-01'
GROUP BY user_id;

-- Add index to improve performance
CREATE INDEX idx_transactions_created_at
ON transactions(created_at);

-- After: Fast query (< 2 seconds)
-- Same query, now uses index

3. Implement Caching:

const redis = require('redis')
const client = redis.createClient()

app.get('/api/expensive-data', async (req, res) => {
  const cacheKey = `data:${req.params.id}`

  // Check cache first
  const cached = await client.get(cacheKey)
  if (cached) {
    return res.json(JSON.parse(cached)) // < 10ms
  }

  // If not cached, compute (may take 60s)
  const data = await expensiveComputation(req.params.id)

  // Cache for 1 hour
  await client.setex(cacheKey, 3600, JSON.stringify(data))

  res.json(data)
})
```javascript

**4. Optimize Queries:**

```javascript
// Bad: N+1 query problem (100+ database calls)
app.get('/api/posts', async (req, res) => {
  const posts = await db.query('SELECT * FROM posts LIMIT 100')

  for (let post of posts) {
    post.author = await db.query('SELECT * FROM users WHERE id = ?', [post.author_id])
  }

  res.json(posts) // Takes 50+ seconds
})

// Good: Single join query (1 database call)
app.get('/api/posts', async (req, res) => {
  const posts = await db.query(`
    SELECT posts.*, users.name as author_name
    FROM posts
    JOIN users ON posts.author_id = users.id
    LIMIT 100
  `)

  res.json(posts) // Takes < 1 second
})

5. Use Streaming Responses:

// For large responses, stream instead of buffering
app.get('/api/large-export', (req, res) => {
  res.setHeader('Content-Type', 'text/csv')
  res.setHeader('Transfer-Encoding', 'chunked')

  // Start sending immediately
  res.write('id,name,email\n')

  // Stream results as they're fetched
  db.stream('SELECT * FROM users')
    .on('data', (row) => {
      res.write(`${row.id},${row.name},${row.email}\n`)
    })
    .on('end', () => {
      res.end()
    })

  // Total time can exceed 100s, but Cloudflare sees active streaming
})
```javascript

## Monitoring and Prevention

**Application Performance Monitoring:**

```javascript
// Track request processing time
app.use((req, res, next) => {
  const start = Date.now()

  res.on('finish', () => {
    const duration = Date.now() - start

    // Log slow requests
    if (duration > 30000) {
      // 30 seconds
      console.warn(`Slow request: ${req.method} ${req.path} took ${duration}ms`)

      // Send alert if approaching timeout
      if (duration > 80000) {
        // 80 seconds
        alertSlowRequest({
          path: req.path,
          duration,
          rayId: req.headers['cf-ray']
        })
      }
    }

    // Record metric
    metrics.histogram('request.duration', duration, {
      method: req.method,
      path: req.path
    })
  })

  next()
})

Database Query Monitoring:

// Monitor slow queries
const logSlowQuery = (query, duration) => {
  if (duration > 5000) {
    // 5 seconds
    console.warn(`Slow query (${duration}ms): ${query}`)

    // Store for analysis
    slowQueryLog.push({
      query,
      duration,
      timestamp: new Date()
    })
  }
}

// Usage with query wrapper
async function executeQuery(sql, params) {
  const start = Date.now()
  const result = await db.query(sql, params)
  const duration = Date.now() - start

  logSlowQuery(sql, duration)

  return result
}
```javascript

**Set Request Timeouts:**

```javascript
// Node.js - Set server timeout
const server = app.listen(3000)
server.timeout = 90000 // 90 seconds (before Cloudflare's 100s)

// If request takes > 90s, fail fast
server.on('timeout', (socket) => {
  console.error('Request timeout - will likely cause 524')
  socket.destroy()
})

// Express route-level timeout
const timeout = require('connect-timeout')

app.get('/api/slow-endpoint', timeout('90s'), (req, res) => {
  if (req.timedout) {
    return res.status(503).json({
      error: 'Request timeout',
      message: 'Processing took too long'
    })
  }
  // Handle request...
})

Try It Yourself

Visit our request builder to learn about 524 errors:

  1. Understand timeout scenarios
  2. Learn optimization techniques
  3. Review async processing patterns
  4. Test performance monitoring

Frequently Asked Questions

What does Cloudflare error 524 mean?

A 524 error means Cloudflare connected to your origin server but the server took too long to respond with HTTP headers. The default timeout is 100 seconds.

How do I fix a 524 error?

Optimize slow server-side operations, add database indexes, implement caching, use background jobs for long tasks, or upgrade to Cloudflare Enterprise for longer timeouts.

What is the difference between 522 and 524?

522 means the TCP connection timed out (could not connect). 524 means the connection succeeded but the HTTP response timed out (connected but server too slow).

Can I increase the Cloudflare timeout?

The 100-second timeout is fixed on Free, Pro, and Business plans. Enterprise plans can request longer timeouts. Consider optimizing your application instead.

Keep Learning