Skip to content

Commit 7f0183e

Browse files
trivikrBridgeAR
authored andcommitted
http2: setting shuttingDown=true after validation
In shutdown(), shuttingDown was set to true before validating options. If invalid options are passed, error was thrown and server remained in shuttingDown state. This code change fixes it. PR-URL: #15676 Fixes: #15666 Refs: #14985 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent f547db1 commit 7f0183e

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

lib/internal/http2/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,6 @@ class Http2Session extends EventEmitter {
983983
if (this[kState].shutdown || this[kState].shuttingDown)
984984
return;
985985

986-
debug(`[${sessionName(this[kType])}] initiating shutdown`);
987-
this[kState].shuttingDown = true;
988-
989986
const type = this[kType];
990987

991988
if (typeof options === 'function') {
@@ -1023,6 +1020,9 @@ class Http2Session extends EventEmitter {
10231020
options.lastStreamID);
10241021
}
10251022

1023+
debug(`[${sessionName(this[kType])}] initiating shutdown`);
1024+
this[kState].shuttingDown = true;
1025+
10261026
if (callback) {
10271027
this.on('shutdown', callback);
10281028
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const http2 = require('http2');
7+
8+
const server = http2.createServer();
9+
10+
const optionsToTest = {
11+
opaqueData: 'Uint8Array',
12+
graceful: 'boolean',
13+
errorCode: 'number',
14+
lastStreamID: 'number'
15+
};
16+
17+
const types = {
18+
boolean: true,
19+
number: 1,
20+
object: {},
21+
array: [],
22+
null: null,
23+
Uint8Array: Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5])
24+
};
25+
26+
server.on(
27+
'stream',
28+
common.mustCall((stream) => {
29+
Object.keys(optionsToTest).forEach((option) => {
30+
Object.keys(types).forEach((type) => {
31+
if (type === optionsToTest[option]) {
32+
return;
33+
}
34+
common.expectsError(
35+
() =>
36+
stream.session.shutdown(
37+
{ [option]: types[type] },
38+
common.mustNotCall()
39+
),
40+
{
41+
type: TypeError,
42+
code: 'ERR_INVALID_OPT_VALUE',
43+
message: `The value "${String(types[type])}" is invalid ` +
44+
`for option "${option}"`
45+
}
46+
);
47+
});
48+
});
49+
stream.session.destroy();
50+
})
51+
);
52+
53+
server.listen(
54+
0,
55+
common.mustCall(() => {
56+
const client = http2.connect(`http://localhost:${server.address().port}`);
57+
const req = client.request();
58+
req.resume();
59+
req.on('end', common.mustCall(() => server.close()));
60+
})
61+
);

0 commit comments

Comments
 (0)