<h4 dir="auto">Describe the bug</h4>
<p dir="auto">I observe a memory leak when I request a file and pipe to another request and I get the error "Request body larger than maxBodyLength limit"</p>
<h4 dir="auto">To Reproduce</h4>
<p dir="auto">To reproduce the problem, I request a file of 20MB and pipe to another request.<br>
Bellow there a sample code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const optsGetFile = {
  method: &quot;get&quot;,
  url: &quot;http://localhost:7001/download&quot;,
  responseType: &quot;stream&quot;,
};
const optsUploadFile = {
  method: &quot;post&quot;,
  url: &quot;http://localhost:7001/upload&quot;,
};

axios(optsGetFile)
  .then(({ headers, data }) =&gt; {
    return axios(_.assign(optsUploadFile, { data, headers }));
  })
"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">optsGetFile</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">method</span>: <span class="pl-s">"get"</span><span class="pl-kos">,</span>
  <span class="pl-c1">url</span>: <span class="pl-s">"http://localhost:7001/download"</span><span class="pl-kos">,</span>
  <span class="pl-c1">responseType</span>: <span class="pl-s">"stream"</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">optsUploadFile</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">method</span>: <span class="pl-s">"post"</span><span class="pl-kos">,</span>
  <span class="pl-c1">url</span>: <span class="pl-s">"http://localhost:7001/upload"</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-en">axios</span><span class="pl-kos">(</span><span class="pl-s1">optsGetFile</span><span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">{</span> headers<span class="pl-kos">,</span> data <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-en">axios</span><span class="pl-kos">(</span><span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-en">assign</span><span class="pl-kos">(</span><span class="pl-s1">optsUploadFile</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> data<span class="pl-kos">,</span> headers <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">The entire test code is present at <a href="https://github.com/jose-lopes/test_axios">https://github.com/jose-lopes/test_axios</a> .<br>
Next I will describe the environment that I setup to reproduce the problem.</p>
<ul dir="auto">
<li>Start fake server. (This program serve /upload and /download (20MB) requests)</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="node test_fakeserver.js"><pre class="notranslate"><code class="notranslate">node test_fakeserver.js
</code></pre></div>
<ul dir="auto">
<li>Start test server and monitor memory with <a href="https://pypi.org/project/memory-profiler/" rel="nofollow">memory-profiler</a>. (This program serve /record request, which it get /download and post to /upload)</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mprof run node test.js"><pre class="notranslate"><code class="notranslate">mprof run node test.js
</code></pre></div>
<ul dir="auto">
<li>execute 20 /record requests with interval of 30 seconds</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="for test in $(seq 1 20); do curl -X POST localhost:7000/record; sleep 30; done"><pre class="notranslate"><code class="notranslate">for test in $(seq 1 20); do curl -X POST localhost:7000/record; sleep 30; done
</code></pre></div>
<ul dir="auto">
<li>Stop test server and execute mprof plot to check memory behavior.</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mprof plot"><pre class="notranslate"><code class="notranslate">mprof plot
</code></pre></div>
<h4 dir="auto">Expected behavior</h4>
<p dir="auto">I expected no memory leak even when we got the error "Request body larger than maxBodyLength limit".<br>
I executed again the test server with option maxBodyLength: 30<em>1024</em>1024 and I got no memory leak.</p>
<h4 dir="auto">Environment</h4>
<ul dir="auto">
<li>Axios Version: 0.21.0</li>
<li>Node.js Version: v14.15.0</li>
<li>OS: Arch Linux</li>
</ul>
<h4 dir="auto">Additional context/Screenshots</h4>
<p dir="auto">Graph when I execute to reproduce:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://raw.githubusercontent.com/jose-lopes/test_axios/master/images/test.png"><img src="https://raw.githubusercontent.com/jose-lopes/test_axios/master/images/test.png" alt="Test Result" style="max-width: 100%;"></a></p>
<h4 dir="auto">Describe the bug</h4>
<p dir="auto">I observe a memory leak when I pipe two requests with a file and I get the error "Request body larger than maxBodyLength limit"</p>
<h4 dir="auto">To Reproduce</h4>
<p dir="auto">To reproduce the problem, I request a file of 20MB and pipe to another request.<br>
Bellow there a sample code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const optsGetFile = {
  method: &quot;get&quot;,
  url: &quot;http://localhost:7001/download&quot;,
  responseType: &quot;stream&quot;,
};
const optsUploadFile = {
  method: &quot;post&quot;,
  url: &quot;http://localhost:7001/upload&quot;,
};

axios(optsGetFile)
  .then(({ headers, data }) =&gt; {
    return axios(_.assign(optsUploadFile, { data, headers }));
  })
"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">optsGetFile</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">method</span>: <span class="pl-s">"get"</span><span class="pl-kos">,</span>
  <span class="pl-c1">url</span>: <span class="pl-s">"http://localhost:7001/download"</span><span class="pl-kos">,</span>
  <span class="pl-c1">responseType</span>: <span class="pl-s">"stream"</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">optsUploadFile</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">method</span>: <span class="pl-s">"post"</span><span class="pl-kos">,</span>
  <span class="pl-c1">url</span>: <span class="pl-s">"http://localhost:7001/upload"</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-en">axios</span><span class="pl-kos">(</span><span class="pl-s1">optsGetFile</span><span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">{</span> headers<span class="pl-kos">,</span> data <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-en">axios</span><span class="pl-kos">(</span><span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-en">assign</span><span class="pl-kos">(</span><span class="pl-s1">optsUploadFile</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> data<span class="pl-kos">,</span> headers <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">The entire test code is present at <a href="https://github.com/jose-lopes/test_axios">https://github.com/jose-lopes/test_axios</a> .<br>
Next I will describe the environment that I setup to reproduce the problem.</p>
<ul dir="auto">
<li>Start fake server. (This program serve /upload and /download (20MB) requests)</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="node test_fakeserver.js"><pre class="notranslate"><code class="notranslate">node test_fakeserver.js
</code></pre></div>
<ul dir="auto">
<li>Start test server and monitor memory with <a href="https://pypi.org/project/memory-profiler/" rel="nofollow">memory-profiler</a>. (This program serve /record request, which it get /download and post to /upload)</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mprof run node test.js"><pre class="notranslate"><code class="notranslate">mprof run node test.js
</code></pre></div>
<ul dir="auto">
<li>execute 20 /record requests with interval of 30 seconds</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="for test in $(seq 1 20); do curl -X POST localhost:7000/record; sleep 30; done"><pre class="notranslate"><code class="notranslate">for test in $(seq 1 20); do curl -X POST localhost:7000/record; sleep 30; done
</code></pre></div>
<p dir="auto">The execution produces the next graph:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://raw.githubusercontent.com/jose-lopes/test_axios/master/images/test.png"><img src="https://raw.githubusercontent.com/jose-lopes/test_axios/master/images/test.png" alt="Test Result" style="max-width: 100%;"></a></p>
<h4 dir="auto">Expected behavior</h4>
<p dir="auto">I expected no memory leak even we got the error "Request body larger than maxBodyLength limit".<br>
I executed again the test with option maxBodyLength: 30<em>1024</em>1024 and got the next graph without memory leak.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://raw.githubusercontent.com/jose-lopes/test_axios/master/images/testExpected.png"><img src="https://raw.githubusercontent.com/jose-lopes/test_axios/master/images/testExpected.png" alt="Test Result" style="max-width: 100%;"></a></p>
<h4 dir="auto">Environment</h4>
<ul dir="auto">
<li>Axios Version: 0.21.0</li>
<li>Node.js Version: v14.15.0</li>
<li>OS: Arch Linux</li>
</ul>
<h4 dir="auto">Additional context/Screenshots</h4>