question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak with responseType: 'text' and 'Content-Type': 'text/html'

See original GitHub issue

Describe the bug Hello, I don’t know if it’s a V8 issue or Axios issue. When I send a get request to get HTML content on a page, a memory leak appear : the html is never stored in garbage collector…

To Reproduce I create a simple server.js with express and axios client to test outside of my project:

const express = require('express');
const axios = require('axios');

const server = express();
const axiosClient = axios.create();

server.get('/axios-test-html', async (req, res) => {
  try {
    const data = await axiosClient.get('https://github.com/winstonjs/winston-daily-rotate-file/pull/185', {
      responseType: 'text',
    });
    const htmlResponse = data.data;
    return res.send({
      sourceCode: htmlResponse,
    });
  } catch (error) {
    console.log(error);
    return res.status(500).send(error);
  }
})

server.listen('4242', () => {
  console.log('server listen at 4242');
});

process.on('SIGINT', () => {
  console.log('server signint');
  process.exit(0);
});
capture d ecran 2019-02-12 a 10 38 29

I’ve running my server.js with node --inspect and create heap snapshots at the beginning and after 3/4 calls.

Expected behavior Normally a memory leak does not appear with json content, but with html yes.

Environment:

  • Axios Version [e.g. 0.18.0]
  • OS: 10.14
  • Browser: Chrome
  • Browser: Version 71.0.3578.98
  • Node.JS : 10.14.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
Tarabytecommented, Feb 14, 2019

@mehdibeldji Before PR is merged (if it ever would be 🤣 ) you could pass a custom response transformer that does nothing. This should eliminate the leak.

const axiosClient = axios.create({
  transformResponse: function(data, headers) {
    // use JSON.parse only if headers['content-type'].includes('application/json')
    // or always return data if you don't plan to use this client to fetch json
    return data 
  }
});
2reactions
Tarabytecommented, Feb 14, 2019

This seems to be V8 issue caused by JSON.parse. I’ve filed a bugreport.

The simplest way to reproduce the issue w/o axios

setInterval(() => {
  const hugeNonJSONString = '*'.repeat(10 ** 6)

  try {
    JSON.parse(hugeNonJSONString)
  } catch (ignored) {
    // swallow
  }
}, 1000)
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Memory Leak while parsing html page source with ...
So, the basic idea is to make get request to certain list URLs and parse text from those page sources by ...
Read more >
4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
In this article we will explore common types of memory leaks in client-side ... 'http://some.url/image'; button.click(); console.log(text.
Read more >
Memory Leaks Demystified - Node.dev
Tracking down memory leaks in Node.js has been a recurring topic, ... writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }) res.write(`Enjoy!
Read more >
dwm.exe (Desktop Window Manager) Produces a Memory ...
Describes an issue where drivers newer than 24.20.100.6290 are causing dwm.exe (Desktop Windows Manager) to produce memory leaks.
Read more >
Memory Leak in Python requests - GeeksforGeeks
It's a type of resource leak or wastage. When there is a memory leak in the application, the memory of the machine gets...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found