Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read body to avoid memory leaks #91

Merged
merged 1 commit into from
Apr 10, 2023
Merged

read body to avoid memory leaks #91

merged 1 commit into from
Apr 10, 2023

Conversation

ykzts
Copy link
Contributor

@ykzts ykzts commented Apr 10, 2023

undici fetch and node-fetch maintain the connection until the body is read, causing a memory leak if the body is not read12.

In this Pull Request, if a 304 is returned or an error is returned, a meaningless res.arrayBuffer (slow because res.json and res.text are parsed together) is executed to read the body.

Footnotes

  1. https://github.com/nodejs/undici/blob/v5.21.2/README.md#garbage-collection

  2. Memory leak when body is not used node-fetch/node-fetch#83

@changeset-bot
Copy link

changeset-bot bot commented Apr 10, 2023

🦋 Changeset detected

Latest commit: d4ab440

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@vercel/edge-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dferber90 dferber90 requested a review from a team April 10, 2023 10:39
@dferber90
Copy link
Collaborator

This is simply brilliant, thank you a lot for bringing this to our attention and fixing it :10-10:

@dferber90 dferber90 merged commit b8d26e9 into vercel:main Apr 10, 2023
@ykzts ykzts deleted the gc branch April 10, 2023 10:50
@dferber90
Copy link
Collaborator

I'm asking around internally to see if we need to apply a similar workaround in index.edge.ts which runs in our Edge Functions / Edge Runtime and I'll release v0.1.7 once that's clarified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants