undici
undici copied to clipboard
Default fetch timeout too short
By default fetch times out after 30 seconds. This causes issues like https://github.com/nodejs/undici/issues/1248
Chrome has 300 second time out.
Please set default unidici fetch timeout to 300 seconds by default.
@ronag Would it make sense to change default request timeout undici-wide to 120 seconds (presumably like in Node.js) or 300 seconds (like in Chrome)?
What's the current timeout?
30 seconds
Sure thing, let's bring it at least to 120 to match Node.js.
https://github.com/nodejs/undici/pull/1384
Now that https://github.com/nodejs/undici/pull/1386 was merged, should this be closed?
The default time out is only 30 seconds again? I don't see 5 minutes anymore set in lib/fetch/index.js
.
@mcollina
The default time out is only 30 seconds again? I don't see 5 minutes anymore set in
lib/fetch/index.js
.@mcollina
That caused other problems... See https://github.com/nodejs/undici/pull/1870
I would suggest we bump the undici defaults then...
The problem is that we're using undici fetch bundled with Node.js. Is there even a way to override this in such case?
Setting to Chrome default 5 minutes would be great.
In the mean time, can we use undici
package to override like this?
const { fetch, Agent } = require('undici');
fetch(webservicesUrl, {
dispatcher: new Agent({
bodyTimeout: 10 * 60e3, // 10 minutes
}
});
You can make Node.js fetch use a custom dispatcher with:
globalThis[Symbol.for('undici.globalDispatcher.1')] = dispatcher;
@targos I'm sorry, that's above my level of knowledge. So how would I override the bodyTimeout with custom dispatcher and fetch bundled with Node.js?
@ronag https://github.com/nodejs/undici/pull/1924
I'm also interested in learning how to override the headersTimeout
when using Node's fetch()
. I just tried
globalThis[Symbol.for("undici.globalDispatcher.1")] = new Agent({
headersTimeout: 10000,
});
inspired by @targos ' suggestion above, and
http.globalAgent = new Agent({
headersTimeout: 10000,
});
but none seemed to have any effect. I need a timeout longer than 300s but used 10s here just for testing. In both cases Agent
is imported from undici as Node's Agent
doesn't have the headersTimeout
option available.
This is really frustrating. For now I'm "patching" all of my occurrences of fetch
with
import { fetch } from 'undici'
wherever I run requests that might validly take longer than 30 seconds to resolve.
This is becoming an issue with AI requests.