Skip to content

Commit 4c24a82

Browse files
FlarnaBethGriggs
authored andcommitted
http2: fix sequence of error/close events
Correct sequence of emitting `error` and `close` events for a `Http2Stream`. PR-URL: #24789 Refs: #22850 Refs: #24685 Fixes: #24559 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 394cb42 commit 4c24a82

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/internal/http2/core.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1997,9 +1997,8 @@ class Http2Stream extends Duplex {
19971997
// will destroy if it has been closed and there are no other open or
19981998
// pending streams.
19991999
session[kMaybeDestroy]();
2000-
process.nextTick(emit, this, 'close', code);
20012000
callback(err);
2002-
2001+
process.nextTick(emit, this, 'close', code);
20032002
}
20042003
// The Http2Stream can be destroyed if it has closed and if the readable
20052004
// side has received the final chunk.

test/parallel/test-http2-stream-destroy-event-order.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Flags: --expose-http2
21
'use strict';
32

43
const common = require('../common');
@@ -10,8 +9,8 @@ let client;
109
let req;
1110
const server = http2.createServer();
1211
server.on('stream', common.mustCall((stream) => {
13-
stream.on('close', common.mustCall(() => {
14-
stream.on('error', common.mustCall(() => {
12+
stream.on('error', common.mustCall(() => {
13+
stream.on('close', common.mustCall(() => {
1514
server.close();
1615
}));
1716
}));
@@ -22,8 +21,8 @@ server.listen(0, common.mustCall(() => {
2221
client = http2.connect(`http://localhost:${server.address().port}`);
2322
req = client.request();
2423
req.resume();
25-
req.on('close', common.mustCall(() => {
26-
req.on('error', common.mustCall(() => {
24+
req.on('error', common.mustCall(() => {
25+
req.on('close', common.mustCall(() => {
2726
client.close();
2827
}));
2928
}));

0 commit comments

Comments
 (0)