Skip to content

Commit

Permalink
http2: fix sequence of error/close events
Browse files Browse the repository at this point in the history
Correct sequence of emitting `error` and `close` events for a
`Http2Stream`.

PR-URL: #24789
Refs: #22850
Refs: #24685
Fixes: #24559
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
Flarna authored and BethGriggs committed Dec 11, 2018
1 parent 394cb42 commit 4c24a82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
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
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

0 comments on commit 4c24a82

Please sign in to comment.