DB / HTTP/Web Servers / 408
WARNING
HTTP/Web Servers Request Timeout
The HTTP 408 status code indicates the server timed out while waiting for the client to send a complete request within its configured time limit.
Common Causes
- Slow network connection causing request transmission delays
- Client-side issues preventing complete request submission
- Server timeout configuration set too low for the request type
- Network infrastructure (proxies, load balancers) timing out requests
- Client application bugs causing request transmission stalls
How to Fix
1 Increase Server Timeout Settings
Configure your web server to allow longer request processing times.
BASH
$ # Nginx
client_header_timeout 60s;
client_body_timeout 60s;
# Apache
Timeout 60
# Node.js/Express
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ extended: true, limit: '50mb' })); 2 Optimize Client Request Handling
Implement client-side timeout handling and request optimization.
BASH
$ # JavaScript fetch with timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 30000);
fetch('/api/endpoint', {
signal: controller.signal,
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
})
.then(response => {
clearTimeout(timeoutId);
return response.json();
})
.catch(error => {
if (error.name === 'AbortError') {
console.error('Request timed out');
}
}); 3 Check Network Infrastructure
Verify proxy, load balancer, and firewall configurations aren't causing premature timeouts.
BASH
$ # Check proxy timeout settings
# For HAProxy
defaults
timeout client 60s
timeout server 60s
timeout connect 10s
# For AWS ALB
# Check idle timeout settings in AWS Console
# Default is 60 seconds, can be increased to 400 seconds 4 Monitor and Debug Request Flow
Use network monitoring tools to identify where the timeout occurs.
BASH
$ # Use curl with verbose output and timeout settings
curl -v --max-time 30 --connect-timeout 10 https://example.com/api
# Use tcpdump to capture network traffic
sudo tcpdump -i any port 80 or port 443 -w capture.pcap
# Check server logs for timeout patterns
tail -f /var/log/nginx/error.log | grep "408" 5 Implement Retry Logic with Backoff
Add intelligent retry mechanisms for transient timeout errors.
BASH
$ import time
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
session = requests.Session()
retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[408, 500, 502, 503, 504],
allowed_methods=["GET", "POST"]
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("http://", adapter)
session.mount("https://", adapter)
response = session.get('https://api.example.com/data', timeout=30)