Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda