-
Link to the code that reproduces this issuehttps://github.com/kamdubiel/next-fetch To ReproduceI 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.
Current vs. Expected behaviorCurrent: Expected: Provide environment informationFrom 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 contextI 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. I think I checked all the other similar issues like: |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 12 replies
-
We faced this problem in our platform, And we fixed it by downgrading node js to 20.15.1. |
Beta Was this translation helpful? Give feedback.
-
Hey @kamdubiel I wonder if it's the |
Beta Was this translation helpful? Give feedback.
-
@khuezy I tested without @hahmadzadeh Thank you for that, indeed Unfortunately |
Beta Was this translation helpful? Give feedback.
-
undici's fetch seems to be a nightmare. Have you notified the node team of the leaks happening to that library? There's this: https://undici.nodejs.org/#/?id=garbage-collection but your repo is consuming the body... so something else in node is leaking 🤷 |
Beta Was this translation helpful? Give feedback.
-
@kamdubiel Thank you for submitting an issue and thanks for taking a look everyone! Since this seems to be a Node issue and not a Next.js issue, I will be converting this to a discussion for further discussion in case anyone else comes across this. |
Beta Was this translation helpful? Give feedback.
-
@samcx I think I can reproduce this locally. I created the same handler in vanilla node and next. The memory usage in Next + Node 20.16.0 increases until it crashes whereas Next + Node 20.15.1 does not have the same issue. Additionally, neither of the vanilla Node version show the same behavior so I think this likely has something to do with modifications that next makes on top of the fetch function (for caching?). Nextimport { headers } from "next/headers";
export default async function Page() {
const res = await fetch("http://counting-service:9001", {
headers: headers(),
});
const { count } = await res.json();
return <pre>{count}</pre>;
} Nodeimport http from "node:http";
http
.createServer(async (req, res) => {
const response = await fetch("http://counting-service:9001", {
headers: req.headers,
});
const { count } = await response.json();
res.writeHead(200, { "Content-Type": "text/html" });
res.end(`<pre>${count}</pre>`);
})
.listen(3000); The reproduction requires |
Beta Was this translation helpful? Give feedback.
-
Same problem here with Next.js and Node v20.16 and v20.17 |
Beta Was this translation helpful? Give feedback.
possible fix nodejs/undici#3445