Skip to content

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

@trivikr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues or PRs related to the http2 subsystem.questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions