diff --git a/.changeset/cool-breads-dream.md b/.changeset/cool-breads-dream.md new file mode 100644 index 0000000..b593ab1 --- /dev/null +++ b/.changeset/cool-breads-dream.md @@ -0,0 +1,5 @@ +--- +'fetch-nodeshim': patch +--- + +Add sane default timeout to `http.request` diff --git a/src/agent.ts b/src/agent.ts index 4d6d373..31b2bd9 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -57,7 +57,7 @@ const matchesNoProxy = (options: { } }; -const defaultAgentOpts = { +export const defaultAgentOpts = { keepAlive: true, keepAliveMsecs: 1000, }; @@ -145,7 +145,7 @@ const createRequestOptions = ( setHost: false, agent: false, proxyEnv: {}, - timeout: 8_000, + timeout: 5_000, headers: proxyHeaders, servername: proxy.protocol === 'https:' ? proxy.hostname : undefined, }; diff --git a/src/fetch.ts b/src/fetch.ts index acd9881..2520387 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -127,6 +127,7 @@ async function _fetch( ); const requestOptions = { ...urlToHttpOptions(requestUrl), + timeout: 5_000, method: methodToHttpOption( initFromRequest ? input.method : requestInit?.method ),