vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.75k stars 26.85k forks source link

Pages router API routes memory leak #56100

Open SooOverpowered opened 1 year ago

SooOverpowered commented 1 year ago

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/stoic-shadow-pzvg4w?file=%2Fpages%2Fapi%2Fupload.js%3A13%2C3

To Reproduce

  1. Start the production server
  2. Open the url
  3. Select a very large file (4GB or above) and click upload

Current vs. Expected behavior

When an upload fails, the data stored inside memory for the failed API call should be freed (.i.e through garbage collection or somthing else). However it stays inside the memory indefinitely.

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:39:54 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T8112
Binaries:
  Node: 18.18.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 7.14.0
Relevant Packages:
  next: 13.5.3
  eslint-config-next: 13.5.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

I tested this on CodeSanbox, local machine, inside k8s, inside docker, all showing the same problem.

alex-statsig commented 8 months ago

@SooOverpowered any update on this? I'm very surprised to not see a response on here from nextjs for such a big issue. We've been chasing down memory leaks for a while and I wonder if this is a root issue.

SooOverpowered commented 8 months ago

@alex-statsig Hi, I think my codesandbox url is broken, but I think you can replicate it by setting up some kind of file upload to an API route, and try uploading a large file then interrupt the upload. As per my testing with NextJS 13 and earlier version of Next 14, the memory was not released.

alex-statsig commented 7 months ago

Have you just been accepting the memory leak then? The lack of response from nextjs team on issues like this astounds me 😞