Skip to content

Unexpected memory usage #2783

@maurocchi

Description

@maurocchi

Describe the bug

I observe a potential memory leak while posting data from a stream using Axios.

To Reproduce

Having a fake server (nc -kl localhost 5000), let's profile this simple script:

mprof run -C -T1 timeout 60 node test_axios.js < /dev/urandom
// test_axios.js
const axios = require("axios");
const followRedirects = require("follow-redirects");
followRedirects.maxBodyLength = Number.MAX_SAFE_INTEGER;
axios.post("http://localhost:5000", process.stdin);

This produces the following chart:
test_axios

Expected behavior

Then consider the following equivalent axios-agnostic script:

const http = require("http");
const options = {
  host: "localhost",
  port: "5000",
  path: "/",
  method: "POST"
};
const req = http.request(options, res => {});
process.stdin.pipe(req);

It produces:
test_http

Here the memory is properly garbaged.

Environment:

  • Axios Version [e.g. 0.19.2]
  • OS: Ubuntu 18.04.4
  • Profiling tool: memory-profiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions