How to Configure HAProxy Timeouts
Timeouts in HAProxy protect resources by terminating idle or slow connections. Proper timeout configuration balances user experience with resource protection. This guide walks through the specific troubleshooting steps to diagnose and resolve timeout issues.
Before You Begin
Before you begin, be sure to have the following in place:
- A Linux server with the relevant software installed
- Access to the command line interface
- Appropriate permissions (root or sudo)
Quick Fix
Wrong
No timeout configuration (uses defaults, which may be too long)
Wrong: No explicit timeouts (using defaults)
Right
timeout connect 5000\ntimeout client 30000\ntimeout server 30000\ntimeout http-request 10000
Right: Explicit timeouts in milliseconds
Output
Timeouts configured:\n Connect: 5s\n Client: 30s\n Server: 30s\n HTTP request: 10s
Prevention
To avoid future issues, follow these best practices:
- Set timeout connect for backend connection establishment
- Set timeout client and timeout server for idle connections
- Set timeout http-request to protect against slow HTTP attacks
- Use timeout queue to limit how long a request waits in queue
- Set timeout tunnel for WebSocket connections
DodaTech Tools
For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.
Common Mistakes with timeout
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world HAPROXY code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro