-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Labels
http2Issues or PRs related to the http2 subsystem.Issues or PRs related to the http2 subsystem.
Description
Version
v16.7.0 (and later)
Platform
Linux mlumish.svl.corp.google.com 5.15.15-1rodete2-amd64 #1 SMP Debian 5.15.15-1rodete2 (2022-02-23) x86_64 GNU/Linux
Subsystem
http2
What steps will reproduce the bug?
const http2 = require('http2');
const {
HTTP2_HEADER_PATH,
HTTP2_HEADER_STATUS,
HTTP2_HEADER_TE,
HTTP2_HEADER_METHOD,
HTTP2_HEADER_AUTHORITY
} = http2.constants;
const server = http2.createServer();
server.on('stream', (stream, headers) => {
setTimeout(() => {
stream.respond({[HTTP2_HEADER_STATUS]: 200});
stream.end('some data');
}, 2000);
});
server.on('session', session => {
setTimeout(() => {
server.close();
session.close();
}, 1000);
});
server.listen(0, () => {
const port = server.address().port;
const client = http2.connect(`http://localhost:${port}`);
const startTime = new Date();
const req = client.request({
[HTTP2_HEADER_PATH]: '/'
});
req.end();
req.on('response', (headers) => {
console.log(headers[HTTP2_HEADER_STATUS]);
});
req.on('data', (chunk) => {console.log('received data')});
req.on('end', () => {console.log('received end')});
req.on('close', () => {
const endTime = new Date();
console.log(`Stream closed with code ${req.rstCode} after ${endTime - startTime}ms`);
});
});
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior?
The correct output, as seen on Node 16.6 and earlier:
200
received data
received end
Stream closed with code 0 after 2018ms
What do you see instead?
received end
Stream closed with code 8 after 2012ms
Additional information
As noted above, this works as expected in Node versions 16.6 and earlier.
This only happens if the stream.respond
call is delayed in the stream
handler. If that is not delayed but stream.end
is delayed, this failure does not occur.
Increasing the delay before responding in the stream
event handler increases the time before the close
event is logged, even though the result of the call is fully determined once the server session is closed, making this bug worse for long-running workloads.
Metadata
Metadata
Assignees
Labels
http2Issues or PRs related to the http2 subsystem.Issues or PRs related to the http2 subsystem.