-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
1 parent
b8c9a4c
commit 2c85d7c
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test/parallel/test-http2-server-shutdown-options-errors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Flags: --expose-http2 | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const http2 = require('http2'); | ||
|
||
const server = http2.createServer(); | ||
|
||
const optionsToTest = { | ||
opaqueData: 'Uint8Array', | ||
graceful: 'boolean', | ||
errorCode: 'number', | ||
lastStreamID: 'number' | ||
}; | ||
|
||
const types = { | ||
boolean: true, | ||
number: 1, | ||
object: {}, | ||
array: [], | ||
null: null, | ||
Uint8Array: Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]) | ||
}; | ||
|
||
server.on( | ||
'stream', | ||
common.mustCall((stream) => { | ||
Object.keys(optionsToTest).forEach((option) => { | ||
Object.keys(types).forEach((type) => { | ||
if (type === optionsToTest[option]) { | ||
return; | ||
} | ||
common.expectsError( | ||
() => | ||
stream.session.shutdown( | ||
{ [option]: types[type] }, | ||
common.mustNotCall() | ||
), | ||
{ | ||
type: TypeError, | ||
code: 'ERR_INVALID_OPT_VALUE', | ||
message: `The value "${String(types[type])}" is invalid ` + | ||
`for option "${option}"` | ||
} | ||
); | ||
}); | ||
}); | ||
stream.session.destroy(); | ||
}) | ||
); | ||
|
||
server.listen( | ||
0, | ||
common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const req = client.request(); | ||
req.resume(); | ||
req.on('end', common.mustCall(() => server.close())); | ||
}) | ||
); |