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

Should invalid options for http2.session.shutdown() be checked before state shuttingDown is updated to true? #15666

Closed
trivikr opened this issue Sep 28, 2017 · 2 comments
Labels
http2 Issues or PRs related to the http2 subsystem. question Issues that look for answers.

Comments

@trivikr
Copy link
Member

trivikr commented Sep 28, 2017

I was writing unit tests for invalid options passed to http2.session.shutdown() as part of #14985 for

if (options.opaqueData !== undefined &&
!isUint8Array(options.opaqueData)) {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'opaqueData',
options.opaqueData);
}
if (type === NGHTTP2_SESSION_SERVER &&
options.graceful !== undefined &&
typeof options.graceful !== 'boolean') {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'graceful',
options.graceful);
}
if (options.errorCode !== undefined &&
typeof options.errorCode !== 'number') {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'errorCode',
options.errorCode);
}
if (options.lastStreamID !== undefined &&
(typeof options.lastStreamID !== 'number' ||
options.lastStreamID < 0)) {
throw new errors.TypeError('ERR_INVALID_OPT_VALUE',
'lastStreamID',
options.lastStreamID);
}

Should we check for invalid options before setting this[kState].shuttingDown to true?

this[kState].shuttingDown = true;

Currently, if there are invalid options:

  • this[kState].shuttingDown is set to true
  • an exception is thrown
  • the session is not shut down.

When shutdown is called for the second time, it returns because of the following check

if (this[kState].shutdown || this[kState].shuttingDown)
return;

In this case, the only way to end the session is to destroy it.

@trivikr trivikr changed the title Should invalid options for http2.session.shutdown() be the first check in the function Should invalid options for http2.session.shutdown() be done before state shuttingDown is updated to true? Sep 28, 2017
@trivikr trivikr changed the title Should invalid options for http2.session.shutdown() be done before state shuttingDown is updated to true? Should invalid options for http2.session.shutdown() be checked before state shuttingDown is updated to true? Sep 28, 2017
@mscdex mscdex added http2 Issues or PRs related to the http2 subsystem. question Issues that look for answers. labels Sep 28, 2017
@apapirovski
Copy link
Member

Good spot! It should definitely be set only after the arguments are validated. Please include it with your PR for the tests, if possible.

@trivikr
Copy link
Member Author

trivikr commented Sep 29, 2017

Thanks @apapirovski
I'll include the fix for this issue with my tests.

I'll set this[kState].shuttingDown to true just after checking for invalid options, and before the callback check:

if (callback) {
this.on('shutdown', callback);
}

trivikr added a commit to trivikr/node that referenced this issue Sep 29, 2017
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.

Refs: nodejs#14985
Fixes: nodejs#15666
@BridgeAR BridgeAR closed this as completed Oct 2, 2017
BridgeAR pushed a commit that referenced this issue Oct 2, 2017
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>
MylesBorins pushed a commit that referenced this issue Oct 3, 2017
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>
MylesBorins pushed a commit that referenced this issue Oct 3, 2017
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>
addaleax pushed a commit to addaleax/ayo that referenced this issue Oct 4, 2017
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: nodejs/node#15676
Fixes: nodejs/node#15666
Refs: nodejs/node#14985
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this issue Oct 11, 2017
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http2 Issues or PRs related to the http2 subsystem. question Issues that look for answers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants