Fully fixes the FD leak by discarding the response stream using resume()
We already discard the result of any GET or POST here, and always have (which we know from the types returning only a status code), so resume() is fine here.
I was under the impression that since we did not provide response.on('data', cb) that this clause wouldn't apply and the response stream would be ignored:
If no 'response' handler is added, then the response will be entirely discarded. However, if a 'response' event handler is added, then the data from the response object must be consumed, either by calling response.read() whenever there is a 'readable' event, or by adding a 'data' handler, or by calling the .resume() method. Until the data is consumed, the 'end' event will not fire. Also, until the data is read it will consume memory that can eventually lead to a 'process out of memory' error.
but of course passing a callback function counts as a handler so in this case the must clause counts and the underlying readable stream was never consumed, causing the FD leak.
This code has been present for many years but only became an issue in Node20. For that, I'm not exactly clear. But I can confirm this PR fixes the issue.
What does this PR do?
Fully fixes the FD leak by discarding the
response
stream usingresume()
We already discard the result of any GET or POST here, and always have (which we know from the types returning only a status code), soresume()
is fine here.I was under the impression that since we did not provide
response.on('data', cb)
that this clause wouldn't apply and the response stream would be ignored:but of course passing a callback function counts as a
handler
so in this case the must clause counts and the underlying readable stream was never consumed, causing the FD leak.This code has been present for many years but only became an issue in Node20. For that, I'm not exactly clear. But I can confirm this PR fixes the issue.
Motivation
You can see the fix in this notebook
Testing Guidelines
Additional Notes
Types of Changes
Check all that apply