Next.js 13 crash with “Error: socket hang up” when use firefox

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;

Leave a Comment