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

150
Vistas
Confusion on memory leaks caused by not clearing the timeout in the fetch handlers

I am reading blog post on Promise.race, fetch and avoiding memory leaks and there is one thing I don't quite understand

The naive implementation he mentioned in the blog post causes a memory leak

const request = fetch(url, options).then(response => response.json());
const timeout = new Promise((_, reject) => {
    setTimeout(() => {
        reject(new Error('Timeout'));
    }, 10000)
});

Promise.race([ request, timeout ]).then(response => {}, error => {})

I understand that the callback we pass to setTimeout holds references to the promise constructor’s function, but what I don't understand is that it in the Heap Snapshot he took at the end of the blog post showing that there are a lot of http.agent and related Socket objects got retained because of the inline setTimout version. Why such an implementation would cause the retaintion of http.agent and Socket objects? I thought it was going to retain the promise constructor’s function and that's it.

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