java
network_error
ai_generated
true
java.net.http.HttpTimeoutException: request timed out
ID: java/http-timeout
82%Fix Rate
86%Confidence
85Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 17 | active | — | — | — |
Root Cause
An HTTP request exceeded its configured timeout (connection timeout or read timeout). Can indicate a slow or unreachable server, network issues, DNS problems, or overly aggressive timeout settings.
genericWorkarounds
-
88% success Configure separate connection and read timeouts with appropriate values and add retry with exponential backoff
1. Set connection timeout to 5-10 seconds (how long to wait for TCP handshake). 2. Set read/response timeout based on expected response time (e.g., 30 seconds for API calls). 3. Implement retry with exponential backoff: 1s, 2s, 4s, with a maximum of 3 retries. 4. Use a library like resilience4j or Spring Retry to handle retry logic cleanly. 5. Add jitter to backoff to avoid thundering herd.
-
85% success Implement circuit breaker pattern for external service calls
1. Use resilience4j CircuitBreaker to wrap HTTP client calls. 2. Configure failure threshold (e.g., open circuit after 5 consecutive timeouts). 3. Set a wait duration before half-opening (e.g., 30 seconds). 4. Provide a fallback response (cached data, default value, or graceful error). 5. Monitor circuit breaker state to detect persistent downstream issues.
Dead Ends
Common approaches that don't work:
-
Setting the timeout to an extremely large value or disabling it entirely
80% fail
Removing timeouts means a single slow request can block a thread indefinitely, leading to thread pool exhaustion and cascading failures across the application. Timeouts are a critical circuit-breaker mechanism.
-
Retrying immediately in a tight loop without backoff
75% fail
If the server is overloaded, aggressive retries make the situation worse. This can trigger rate limiting or cause a retry storm that overwhelms both the client and server.
Error Chain
Preceded by:
Frequently confused with: