Skip to content

Commit bb34b3d

Browse files
johnnymo87claude
andcommitted
Add Undici dispatcher to disable hidden 5-min timeouts
Node's fetch() uses Undici internally, which has hidden headersTimeout and bodyTimeout defaults of 300s (5 min). For long-running requests (4-10+ min), this causes "fetch failed" errors even though our AbortSignal.timeout is 20 min. Solution: Create a custom Undici Agent with both timeouts disabled and pass it as the dispatcher option to fetch(). Ref: nodejs/node#46375 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 22901c3 commit bb34b3d

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎package-lock.json‎

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"test": "node --test src/*.test.js"
1414
},
1515
"dependencies": {
16-
"playwright": "^1.40.0"
16+
"playwright": "^1.40.0",
17+
"undici": "^7.18.2"
1718
}
1819
}

‎src/cli.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@ import fs from 'node:fs';
1010
import crypto from 'node:crypto';
1111
import { spawn } from 'node:child_process';
1212
import { parseArgs } from 'node:util';
13+
import { Agent } from 'undici';
1314

1415
const SERVER_URL = process.env.ASK_QUESTION_SERVER_URL || 'http://127.0.0.1:3033';
1516

17+
// Custom dispatcher to disable Undici's hidden timeouts.
18+
// Node's fetch() uses Undici which defaults headersTimeout and bodyTimeout to
19+
// 300s (5 min). For long-running requests (4-10+ min), this causes "fetch failed"
20+
// errors even though our AbortSignal.timeout is much longer.
21+
const longRequestDispatcher = new Agent({
22+
headersTimeout: 0, // Disable Undici's 5-min header timeout
23+
bodyTimeout: 0, // Disable Undici's body inactivity timeout
24+
});
25+
1626
function usage() {
1727
console.log(`Usage: ask-question [options] [prompt...]
1828
@@ -94,7 +104,8 @@ async function askServer(prompt, opts = {}) {
94104
method: 'POST',
95105
headers: { 'Content-Type': 'application/json' },
96106
body: JSON.stringify({ prompt, timeout, newChat, requestId }),
97-
signal: AbortSignal.timeout(timeout + 10000) // Extra buffer for HTTP overhead
107+
signal: AbortSignal.timeout(timeout + 10000), // Extra buffer for HTTP overhead
108+
dispatcher: longRequestDispatcher, // Disable Undici's 5-min hidden timeouts
98109
});
99110

100111
const data = await res.json();

0 commit comments

Comments
 (0)