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

process: add isExiting #16404

Closed
wants to merge 1 commit into from
Closed

Conversation

bengl
Copy link
Member

@bengl bengl commented Oct 23, 2017

This replaces the previously undocumented _exiting property with a
read-only property giving the same information. Setting the property is
restricted to internals, to prevent tampering. Tampering could affect
nextTick behavior, for example.

Twitter thread for context: https://twitter.com/bengl/status/922361992379166721

It may or may not make sense to keep _exiting around as an alias, if there's userland code using it. That's easy enough to do if reviewers would like that.

/cc @addaleax @Trott

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

process

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 23, 2017
@bengl
Copy link
Member Author

bengl commented Oct 23, 2017

-->

This read-only boolean tells whether the process is currently exiting. That is,
when the `exit` even has been fired and no further scheduled asynchronus code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: asynchronous

const {
getHiddenValue,
setHiddenValue,
is_exiting_private_symbol: kIsExiting
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kIsExitingSymbol? kIsExiting suggests it's a boolean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we using kAnything to signify symbols where, I assume, k === key? At the very least, http2, tls & url already do it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apapirovski k is for konstants ;)

@@ -246,7 +246,7 @@ function setupNextTick() {
if (typeof callback !== 'function')
throw new errors.TypeError('ERR_INVALID_CALLBACK');

if (process._exiting)
if (process.isExiting)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to introduce a performance regression (getter that calls into the C++ runtime.) Have you run next-tick benchmarks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rather than a getter here, a public read-only property should be added only when we are exiting... that is.. setIsExiting() could do something like...

Object.defineProperty(process, 'exiting', { configurable: false, enumerable: true, value: true });

This should largely avoid the perf regression on calling the getter multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell If it weren't there prior to exiting, then it could be set by userland code long before exiting, causing the problems I was trying to solve.

Maybe a getter to something in internal/process? That way it still would be userland tamper-proof, but wouldn't dive into C++.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would certainly be better but the getter still comes at a cost.... hmm will have to think about it a bit more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextTick could just use the actual value on internal/process, rather than the getter (which would be only for public use).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bengl if I understand you correct you want to use a plain symbol in internal/process plus the isExiting property as getter that exposes that symbol?

@Fishrock123
Copy link
Contributor

Why expose this publicly now? The only code that can run during exist is within 'exit' event handlers, right?

If anything we should make the property non-writable-configurable or just hide it entirely...

@addaleax
Copy link
Member

Why expose this publicly now?

For one, it tells you whether there’s a chance async operations that you schedule will finish or not.

The only code that can run during exist is within 'exit' event handlers, right?

Yes, it should tell you exactly that – whether you’re inside an 'exit' handler or not.

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 23, 2017
@jasnell
Copy link
Member

jasnell commented Oct 23, 2017

Defensively marking as semver-major. I've seen code in the wild that looks at process._exiting

@addaleax
Copy link
Member

It may or may not make sense to keep _exiting around as an alias, if there's userland code using it. That's easy enough to do if reviewers would like that.

Yes, I’d think so. It doesn’t really cost anything to keep that around, right?

-->

This read-only boolean tells whether the process is currently exiting. That is,
when the `exit` even has been fired and no further scheduled asynchronus code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. even -> event?
  2. Maybe it is worth to add a type before the description for consistency with other properties:
* {boolean}

@@ -1188,6 +1188,15 @@ console.log(process.getgroups()); // [ 27, 30, 46, 1000 ]
*Note*: This function is only available on POSIX platforms (i.e. not Windows
or Android).

## process.isExiting
<!-- YAML
added: vX.X.X
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vX.X.X -> REPLACEME

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: Maybe some of the cool new md linting can get a custom rule to validate these YAML bits? /cc @watilde

added: vX.X.X
-->

This read-only boolean tells whether the process is currently exiting. That is,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"tells whether" -> "indicates if"?

@BridgeAR
Copy link
Member

I am wondering if we really need to expose this at all... I am not a huge fan of adding functionality that was never requested. Does someone have a use case for me right quick?
Without exposing it we could simply use a plain symbol and do not have to worry about the performance implications anymore as that would not have any.

@addaleax
Copy link
Member

Hm - ping @bengl?

@BridgeAR I think this makes sense just from the perspective of API completeness alone. Without this, you can't tell whether asynchronous work that you're going to schedule will run or not.

@Trott
Copy link
Member

Trott commented Dec 4, 2017

@BridgeAR Here's a use case: #17453

@jasnell
Copy link
Member

jasnell commented Dec 5, 2017

I'm + 1 on adding this and keeping the _exiting around as an alias for a while.

@addaleax
Copy link
Member

addaleax commented Dec 5, 2017

and keeping the _exiting around as an alias for a while.

Or indefinitely. ;)

@addaleax
Copy link
Member

ping @bengl again

This replaces the previously undocumented `_exiting` property with a
read-only property giving the same information. Setting the property is
restricted to internals, to prevent tampering. Tampering could affect
nextTick behavior, for example.
@bengl bengl force-pushed the bengl/processisexiting branch from fc062cc to 1b7a9bf Compare December 10, 2017 23:11
@bengl
Copy link
Member Author

bengl commented Dec 10, 2017

I've updated this with the requested changes, however, as @bnoordhuis suggested, nextTick performance is greatly degraded by this change. I'm going to investigate using internal/process as the canonical location of the boolean.

@addaleax
Copy link
Member

@bengl If necessary, there’s always the option of falling back to just renaming it, right? I would prefer that over trying to protect it from user access at all costs.

@bengl
Copy link
Member Author

bengl commented Dec 11, 2017

@addaleax Yeah, I'd definitely prefer to prevent user tampering, but the added overhead of having to pass an extra reference in so node.cc#EmitExit can set it might not be worth the effort it right now.

I'll do another PR in a bit, just adding the alias and documenting it.

@BridgeAR
Copy link
Member

@bengl is this still work in progress? And it needs a rebase.

@BridgeAR
Copy link
Member

BridgeAR commented Feb 7, 2018

Closing due to long inactivity. Please feel free to reopen if you would like to work on this again.

@BridgeAR BridgeAR closed this Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.