This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Possible memory leak in Fetch API #68578
Labels
bug
Issue was opened via the bug report template.
Output (export/standalone)
Related to the the output option in `next.config.js`.
Performance
Anything with regards to Next.js performance.
Link to the code that reproduces this issue
https://github.com/kamdubiel/next-fetch
To Reproduce
I created simple reproduction with docker compose. There's simple Express API (just to return random JSON data), K6 for stress test and NextJS 14.2.5 with simple dynamic route with async server component.
docker compose up -d
docker stats next
docker compose run k6 run /scripts/ewoks.js
Current vs. Expected behavior
Current:
When container starts, it's memory usage is around ~45MB.
After stress test, the memory usage goes up to ~400MB, and stays there forever. Running more tests will increase the idle memory usage.
Expected:
After stress test, when Next is idling, the memory used should drop.
Provide environment information
From Docker container: Operating System: Platform: linux Arch: x64 Version: #39-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 21:49:14 UTC 2024 Available memory (MB): 63434 Available CPU cores: 16 Binaries: Node: 20.16.0 npm: 10.8.1 Yarn: 1.22.22 pnpm: N/A Relevant Packages: next: 14.2.5 // Latest available version is detected (14.2.5). eslint-config-next: 14.2.5 react: 18.3.1 react-dom: 18.3.1 typescript: 5.5.4 Next.js Config: output: standalone
Which area(s) are affected? (Select all that apply)
Output (export/standalone), Performance
Which stage(s) are affected? (Select all that apply)
next start (local), Other (Deployed)
Additional context
I tested my reproduction code against different Next ~14 versions, canary releases and NodeJS versions. It looks like all the versions since async server components support are affected.
Also, I tested the same code with axios and cross-fetch, and it works correctly, so for me it looks like the issue is with Fetch caching.
I have the same issue in real-world app hosted in AKS, and it causes out of memory errors every few days - is there any way to make the garbage collector clean up memory allocations more aggressively when using native fetch?
I think I checked all the other similar issues like:
#64212
#54708
But I think that my example is much simpler so I decided to create new issue.
The text was updated successfully, but these errors were encountered: