Missing Abort Controller
fetch or axios calls with no timeout, in API routes, server actions and background jobs
infoPerformance
missing-abort-controllerWhy this matters
A fetch without a timeout hangs indefinitely if the remote server is slow or down. Your API route blocks, the connection pool fills up, and your entire server becomes unresponsive.
Example
app/api/data/route.tsexport async function GET() {
const res = await fetch("https://api.example.com/data");
return Response.json(await res.json());
}app/api/data/route.tsexport async function GET() {
const res = await fetch("https://api.example.com/data", {
signal: AbortSignal.timeout(5000),
});
return Response.json(await res.json());
}How to fix
Give every outbound request a timeout: AbortSignal.timeout(ms) for fetch, the timeout option for axios. Five to ten seconds suits most APIs.
Reference
- In the output
- Findings carry
"ruleId": "missing-abort-controller"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line missing-abort-controller- Silence a whole file
// prodlint-disable missing-abort-controllerat the top of the file- How it works
- Matches text patterns. Source on GitHub