Reputation: 41
I have next.js 13 application(with app router) running on k8s with node 18.Server crash when i use firefox to view a feature which gets and display around 10 images(around 170B each).But same function works in chrome browser without causing server crash.When i check the request i noticed firefox passes Connection as keep-alive while chrome doesn't.I use below Dockerfile in deployment. https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile. Below is the exact error i get.
Error: socket hang up at connResetException (node:internal/errors:720:14) at Socket.socketOnEnd (node:_http_client:525:23) at Socket.emit (node:events:526:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ECONNRESET'
Images are displayed with next/image support and also use sharp package for optimization. Code looks similar to below.
{imageList.length > 0
? imageList.map((val, index) => {
return (
<Box flexGrow={1} className="myclass">
<Image
src={val.url}
alt={val.name}
id={index}
width={94}
height={130}
sizes="100vw"
/>
</Box>
})
: null}
I have configure the Keepalive timeout in server as below
server.keepAlive=true
server.keepAliveTimeout=70000
server.headersTimeout=70000+1000
Also i have disable the keep alive config in the server and try. Still I get the error when try with firefox.Further i observe when i decrease the number of images to around 6 i don't get the error in firefox. Also i configured the next.config.js as below
const nextConfig = {output: 'standalone',httpAgentOptions: {keepAlive: true,},};
module.exports = nextConfig;
Update1: Further investigation reveal missing sec-ch-ua-mobile
header in firefox cause this server crash issue. Looks like the next/image fail due to this.
Update2: Came across this nextjs 13 bug
https://github.com/vercel/next.js/issues/51605
Upvotes: 1
Views: 2671
Reputation: 41
This is due to memory leak in Next.js 13. If anyone come across please check the below link for further information. https://github.com/vercel/next.js/issues/49929
According to the link given use the latest canary release. Even after that I had increase the memory.
Upvotes: 0