Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response promise resolves before response closes #642

Closed
medikoo opened this issue May 21, 2019 · 1 comment
Closed

Response promise resolves before response closes #642

medikoo opened this issue May 21, 2019 · 1 comment

Comments

@medikoo
Copy link

medikoo commented May 21, 2019

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 Fetch works in a browser.
  • It seems not possible to observe an async request/response process as a whole (it finalizes with 'close' event emitted on response, which is not exposed and ignored by node-fetch internals). It's an issue when e.g. we want to detect orphaned async flows, and for that want to guarantee that promises returned by fetch do 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();
  });
@bitinn bitinn mentioned this issue Sep 8, 2019
35 tasks
@xxczaki
Copy link
Member

xxczaki commented Apr 21, 2020

This issue should no longer occur in the v3.x release.

@xxczaki xxczaki closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants