1. Library
  2. Http and the Web
  3. Status Codes

Updated 10 hours ago

Most HTTP errors punish you for what you said. This one punishes you for not saying anything at all.

The 408 Request Timeout occurs when a client starts a request but doesn't finish it in time. The server opened the door and waited. You started to speak, then went silent. Eventually, it gave up on you.

The Anatomy of Abandonment

A normal request flows like this:

Client: POST /api/data HTTP/1.1
Client: Content-Type: application/json
Client: Content-Length: 1024
Client: 
Client: {"name": "example", ...}
Server: HTTP/1.1 200 OK

A 408 happens when this flow stalls:

Client: POST /api/data HTTP/1.1
Client: Content-Type: application/json
Client: Content-Length: 1024
Client: 
[silence]
[more silence]
Server: HTTP/1.1 408 Request Timeout
Server: Connection: close

The client promised 1024 bytes. The server waited. The bytes never came.

Why Requests Go Silent

The network fails mid-sentence. You're uploading a file, your WiFi drops, and your half-sent request hangs in limbo.

The client freezes. A browser tab crashes, an app locks up, a script hits an infinite loop—and the server is left waiting for data that will never arrive.

The connection is too slow. A 100MB upload over a 56kbps connection might legitimately take longer than the server is willing to wait.

The client forgets to send the body. Headers say Content-Length: 1024, but the code never actually sends those 1024 bytes.

Server Timeouts: The Patience Configuration

Servers configure how long they'll wait:

# Nginx
client_header_timeout 60s;   # Time to receive headers
client_body_timeout 60s;     # Time to receive body
keepalive_timeout 75s;       # Time to wait for next request

These aren't arbitrary. They protect servers from connections that start but never finish—which would otherwise consume resources indefinitely.

For large uploads, you need more patience:

location /api/upload {
    client_body_timeout 300s;  # 5 minutes for uploads
}

408 vs. 504: Direction Matters

These errors both involve timeouts, but the direction is opposite:

408 Request Timeout: The server is waiting for you to finish talking.

You → (silence) → Server → 408

504 Gateway Timeout: A gateway is waiting for the upstream server to respond.

You → Gateway → (waiting) → Upstream Server
              ↓
             504

408 is about sending. 504 is about receiving.

Handling 408 as a Client

Unlike many 4xx errors, 408 is safe to retry. The problem wasn't your request—it was that your request didn't arrive. Try again:

async function fetchWithRetry(url, options, maxRetries = 3) {
    for(let attempt = 0; attempt < maxRetries; attempt++) {
        const response = await fetch(url, options);
        
        if(response.status === 408 && attempt < maxRetries - 1) {
            await sleep(Math.pow(2, attempt) * 1000); // Exponential backoff
            continue;
        }
        
        return response;
    }
}

For large uploads, stream instead of buffering:

// Don't load entire file into memory
const stream = fs.createReadStream('large-file.bin');
await fetch('/api/upload', { method: 'POST', body: stream });

When 408 Is Wrong

Don't use 408 for slow processing. If your server received the request but is taking forever to generate a response, that's a 503 or 504—not a 408.

// Wrong: Server is slow, not client
HTTP/1.1 408 Request Timeout

// Right: Server is overloaded
HTTP/1.1 503 Service Unavailable

Don't use 408 for bad data. If the client sent garbage, that's 400 Bad Request. 408 means the client didn't send enough, not that what they sent was wrong.

A Proper 408 Response

HTTP/1.1 408 Request Timeout
Connection: close
Retry-After: 60
Content-Type: application/json

{
    "error": "Request Timeout",
    "message": "The server closed the connection after waiting for your request. You can retry."
}

The Connection: close header is important. After a timeout, the connection state is uncertain—better to start fresh.

The Core Truth

408 is the only HTTP error about absence rather than presence. Every other error responds to something you did wrong. This one responds to something you didn't do at all.

The server waited. You didn't show up. It moved on.

Frequently Asked Questions About 408 Request Timeout

Was this page helpful?

😔
🤨
😃
408 Request Timeout • Library • Connected