next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Pages router API routes memory leak

Open SooOverpowered opened this issue 2 years ago • 2 comments
trafficstars

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

  • [X] I verified that the issue exists in the latest Next.js 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.

SooOverpowered avatar Sep 27 '23 16:09 SooOverpowered

@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.

alex-statsig avatar Feb 16 '24 18:02 alex-statsig

@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.

SooOverpowered avatar Feb 17 '24 02:02 SooOverpowered

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

alex-statsig avatar Feb 18 '24 19:02 alex-statsig