Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
IncomingMessage,ServerResponse not garbage collected in keep-alive connections

In the last few days, I've investigated a memory leak issue regarding keep-alive HTTP/1.1 connections in NodeJS 14.17.3.

I have simplified the implementation of the API as shown below.

async function index(req, res) {
  res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    Connection: 'keep-alive',
    'Access-Control-Allow-Credentials': 'true',
    'Access-Control-Expose-Headers':
      'Accept,Accept-Encoding,Accept-Language,Cache-Control,Connection,Host,Origin,Pragma,Referer,Sec-Fetch-Dest,Sec-Fetch-Mode,Sec-Fetch-Site,Sec-GPC,User-Agent',
  });

  res.write('test');

  res.on('close', () => {
    res.end();
  });
}

The issue appears when the client interrupts the connection from his side. Although the 'close' event is fired and the callback is executed successfully, the objects remain in memory. Using the inspect tool of chrome, I took a picture and attached it below.

Memory Snapshot

What I expect is the highlighted ServerResponse object to be garbage collected after the response ends. Also, the 'finish' event is not fired in this case. I do not know if it is relevant or if it is a standard behavior when the request is interrupted by the client.

I use expressjs as the web framework and the reason the connections are 1.1 is that the API is for server-sent events.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda