-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
In some scenarios promise returned by e.g.response.text() resolves before 'close' event is emitted on Node.js response object (as emitted with requests's 'response' event).
It's not an issue per se, but:
- Not sure if that's on par with how
Fetchworks in a browser. - It seems not possible to observe an async request/response process as a whole (it finalizes with
'close'event emitted onresponse, which is not exposed and ignored bynode-fetchinternals). It's an issue when e.g. we want to detect orphaned async flows, and for that want to guarantee that promises returned byfetchdo not resolve prior response closes.
For example following test case will report an async leak in Node.js v12.2, when using node-fetch at v2.6.0
const fetch = require('node-fetch');
const checkAsyncLeak = () =>
setTimeout(() => {
throw new Error('Async leak!');
}).unref();
fetch('https://google.com', { compress: false })
.then(response => response.text())
.then(() => {
// All request related async jobs should be finalized by now
checkAsyncLeak();
});Reactions are currently unavailable