node-modules / urllib

Request HTTP(s) URLs in a complex world.
MIT License
725 stars 115 forks source link

how to config connecttimeout of err UND_ERR_CONNECT_TIMEOUT #466

Closed shanqs123 closed 9 months ago

shanqs123 commented 11 months ago

When server is offline. GET operation will throw this error.

default undici connection timeout is set to 10e3. how could I config the time to 1500ms

ConnectTimeoutError: Connect Timeout Error at onConnectTimeout (D:\Codes\nodeJS\node_modules\undici\lib\core\connect.js:182:24) at D:\Codes\nodeJS\node_modules\undici\lib\core\connect.js:129:46 at Immediate._onImmediate (D:\Codes\nodeJS\node_modules\undici\lib\core\connect.js:168:33) at process.processImmediate (node:internal/timers:476:21) { code: 'UND_ERR_CONNECT_TIMEOUT',

fengmk2 commented 9 months ago

use the timeout options.

timeout Number | Array - Request timeout in milliseconds for connecting phase and response receiving phase. Default is 5000. You can use timeout: 5000 to tell urllib use same timeout on two phase or set them seperately such as timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s.

https://github.com/node-modules/urllib#arguments

fengmk2 commented 9 months ago

I find the missing connect options, I will send a pr to fix this problem.