undici icon indicating copy to clipboard operation
undici copied to clipboard

Default fetch timeout too short

Open kyrylkov opened this issue 2 years ago • 16 comments

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.

kyrylkov avatar Apr 26 '22 12:04 kyrylkov

@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)?

kyrylkov avatar Apr 26 '22 20:04 kyrylkov

What's the current timeout?

mcollina avatar Apr 26 '22 21:04 mcollina

30 seconds

kyrylkov avatar Apr 26 '22 21:04 kyrylkov

Sure thing, let's bring it at least to 120 to match Node.js.

mcollina avatar Apr 26 '22 21:04 mcollina

https://github.com/nodejs/undici/pull/1384

kyrylkov avatar Apr 26 '22 21:04 kyrylkov

Now that https://github.com/nodejs/undici/pull/1386 was merged, should this be closed?

kibertoad avatar May 28 '22 12:05 kibertoad

The default time out is only 30 seconds again? I don't see 5 minutes anymore set in lib/fetch/index.js.

@mcollina

kyrylkov avatar Feb 10 '23 15:02 kyrylkov

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

ronag avatar Feb 10 '23 15:02 ronag

I would suggest we bump the undici defaults then...

ronag avatar Feb 10 '23 15:02 ronag

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
  }
});

kyrylkov avatar Feb 10 '23 15:02 kyrylkov

You can make Node.js fetch use a custom dispatcher with:

globalThis[Symbol.for('undici.globalDispatcher.1')] = dispatcher;

targos avatar Feb 10 '23 16:02 targos

@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?

kyrylkov avatar Feb 10 '23 16:02 kyrylkov

@ronag https://github.com/nodejs/undici/pull/1924

kyrylkov avatar Feb 11 '23 08:02 kyrylkov

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.

pether-b avatar Mar 03 '23 11:03 pether-b

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.

cactysman avatar Apr 03 '23 07:04 cactysman

This is becoming an issue with AI requests.

ralyodio avatar May 20 '23 20:05 ralyodio