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

[v8.x] http2: fix sequence of error/close events #24789

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1997,9 +1997,8 @@ class Http2Stream extends Duplex {
// will destroy if it has been closed and there are no other open or
// pending streams.
session[kMaybeDestroy]();
process.nextTick(emit, this, 'close', code);
callback(err);

process.nextTick(emit, this, 'close', code);
}
// The Http2Stream can be destroyed if it has closed and if the readable
// side has received the final chunk.
Expand Down
43 changes: 43 additions & 0 deletions test/parallel/test-http2-error-order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const { createServer, connect } = require('http2');

const messages = [];
const expected = [
'Stream:created',
'Stream:error',
'Stream:close',
'Request:error'
];

const server = createServer();

server.on('stream', (stream) => {
messages.push('Stream:created');
stream
.on('close', () => messages.push('Stream:close'))
.on('error', (err) => messages.push('Stream:error'))
.respondWithFile('dont exist');
});

server.listen(0);

const client = connect(`http://localhost:${server.address().port}`);
const req = client.request();

req.on('response', common.mustNotCall());

req.on('error', () => {
messages.push('Request:error');
client.close();
});

client.on('close', common.mustCall(() => {
assert.deepStrictEqual(messages, expected);
server.close();
}));
9 changes: 4 additions & 5 deletions test/parallel/test-http2-stream-destroy-event-order.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Flags: --expose-http2
'use strict';

const common = require('../common');
Expand All @@ -10,8 +9,8 @@ let client;
let req;
const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.on('close', common.mustCall(() => {
stream.on('error', common.mustCall(() => {
stream.on('error', common.mustCall(() => {
stream.on('close', common.mustCall(() => {
server.close();
}));
}));
Expand All @@ -22,8 +21,8 @@ server.listen(0, common.mustCall(() => {
client = http2.connect(`http://localhost:${server.address().port}`);
req = client.request();
req.resume();
req.on('close', common.mustCall(() => {
req.on('error', common.mustCall(() => {
req.on('error', common.mustCall(() => {
req.on('close', common.mustCall(() => {
client.close();
}));
}));
Expand Down