Skip to content

Conversation

parfeon
Copy link
Contributor

@parfeon parfeon commented Dec 11, 2024

fix(node-fetch): keepAlive for Node.js 19+

Fix issue because of which node-fetch used default agent, which after Node.js 19+ has keepAlive enabled by default.

Fix issue because of which `node-fetch` used default agent, which after Node.js 19+ has `keepAlive`
enabled by default.
@parfeon parfeon added status: done This issue is considered resolved. priority: medium This PR should be reviewed after all high priority PRs. type: fix This PR contains fixes to existing features. labels Dec 11, 2024
@parfeon parfeon self-assigned this Dec 11, 2024
@parfeon
Copy link
Contributor Author

parfeon commented Dec 11, 2024

In this section of node-fetch docs written the following:

If no agent is specified, the default agent provided by Node.js is used. Note that this changed in Node.js 19 to have keepalive true by default.

In the code, I added this guard:

// Don't configure any agents if keep alive not requested.
if (!this.keepAlive && !this.proxyConfiguration) return undefined;

and with mentioned default behavior, it means that if user will set keepAlive to false we won't set agent and default will be used where in Node.js 19+ keepAlive is set to true by default.

@parfeon parfeon merged commit f51f759 into master Dec 12, 2024
7 checks passed
@parfeon parfeon deleted the CLEN-2402 branch December 12, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium This PR should be reviewed after all high priority PRs. status: done This issue is considered resolved. type: fix This PR contains fixes to existing features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants