typescript.http_missing_timeout
Stability
Medium
Detects HTTP client calls without timeout configuration.
Why It Matters
Section titled “Why It Matters”HTTP requests without timeouts can hang forever:
- Stuck requests — Unresponsive servers block your code
- Resource leaks — Connections held indefinitely
- User experience — Applications become unresponsive
- Cascade failures — One slow service blocks everything
Fetch API has no default timeout.
Example
Section titled “Example”// ❌ Beforeconst response = await fetch(url);If the server is slow, this waits forever.
// ✅ Afterconst controller = new AbortController();const timeout = setTimeout(() => controller.abort(), 30000);
try { const response = await fetch(url, { signal: controller.signal }); return response;} finally { clearTimeout(timeout);}What Unfault Detects
Section titled “What Unfault Detects”fetch()without AbortController- axios without timeout config
- HTTP clients missing timeout
Auto-Fix
Section titled “Auto-Fix”Unfault adds AbortController-based timeout.
Library Patterns
Section titled “Library Patterns”// Axios - built-in timeoutconst response = await axios.get(url, { timeout: 30000});
// Got - built-in timeoutconst response = await got(url, { timeout: { request: 30000 }});
// Helper functionasync function fetchWithTimeout(url: string, ms: number) { const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), ms);
try { return await fetch(url, { signal: controller.signal }); } finally { clearTimeout(timeout); }}