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

redirected HTTP/2 request causes process exit #107

Closed
stefan-guggisberg opened this issue May 29, 2020 · 3 comments
Closed

redirected HTTP/2 request causes process exit #107

stefan-guggisberg opened this issue May 29, 2020 · 3 comments
Labels

Comments

@stefan-guggisberg
Copy link
Contributor

stefan-guggisberg commented May 29, 2020

Requesting a redirected resource over HTTP2 causes sudden process exit with code 0.

Code to reproduce:

const { fetch, disconnectAll } = require('fetch-h2');

const ts0 = Date.now();

process.on('exit', (code) => {
  const ts1 = Date.now();
  console.log(`exited after ${ts1 - ts0} ms with code: ${code}`);
});

(async () => {
  try {
    const url = 'https://nghttp2.org/httpbin/absolute-redirect/1';
    console.log(`fetching ${url} ...`);
    const resp = await fetch(url, {
      redirect: 'follow',
    });
    console.log(`Status: ${resp.status}, HTTP Version: ${resp.httpVersion}, redirected: ${resp.redirected}`);
    console.log(`Body:\n${await resp.text()}`);
  } catch (e) {
    console.error(e);
    throw e;
  } finally {
    await disconnectAll();
  }
})();

Running above code produces the following console output:

fetching https://nghttp2.org/httpbin/absolute-redirect/3 ...
exited after 808 ms with code: 0

The process exits during the fetch call with code 0 (success) because somehow no more async operations were pending.

This is a regression of changes introduced in version 2.4.0. All versions since 2.4.0 are affected. 2.3.0 OTOH does work as expected.

Workarounds:

  • Force HTTP/1(.1): require('fetch-h2').context({ httpsProtocols: ['http1'] })
  • Create an async task which outlives the request (e.g.setTimeout(...))
@stefan-guggisberg
Copy link
Contributor Author

Note: I can't reproduce the issue in a Mocha test. Probably because Mocha runs the tests in forked child processes.

@stefan-guggisberg
Copy link
Contributor Author

@grantila This is a serious issue for us. Could you please have a look or at least direct me to the code that need's to be fixed?

grantila added a commit that referenced this issue Aug 20, 2020
Also fixed async ref issue with http2 relative redirections

fix #107
@github-actions
Copy link

🎉 This issue has been resolved in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant