Skip to content

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

Description

@trivikr

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.

Activity

  1. 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?[/+] on Sep 28, 2017
  2. 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?[/+] on Sep 28, 2017
  3. added
    http2Issues and PRs related to the http2 subsystem.
    questionIssues asking questions about Node.js.
    on Sep 28, 2017
  4. apapirovski commented on Sep 28, 2017

    @apapirovski
    Contributor

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

  5. trivikr commented on Sep 29, 2017

    @trivikr
    MemberAuthor

    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);
    }

  6. added a commit that references this issue on Sep 29, 2017
    50270d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues and PRs related to the http2 subsystem.questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions