-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Labels
Description
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(...))
Reactions are currently unavailable