-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
process: add isExiting #16404
Conversation
doc/api/process.md
Outdated
--> | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: asynchronous
lib/internal/process.js
Outdated
const { | ||
getHiddenValue, | ||
setHiddenValue, | ||
is_exiting_private_symbol: kIsExiting |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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++.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
Why expose this publicly now? The only code that can run during exist is within If anything we should make the property non-writable-configurable or just hide it entirely... |
For one, it tells you whether there’s a chance async operations that you schedule will finish or not.
Yes, it should tell you exactly that – whether you’re inside an |
Defensively marking as semver-major. I've seen code in the wild that looks at |
Yes, I’d think so. It doesn’t really cost anything to keep that around, right? |
doc/api/process.md
Outdated
--> | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- even -> event?
- Maybe it is worth to add a type before the description for consistency with other properties:
* {boolean}
doc/api/process.md
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vX.X.X
-> REPLACEME
There was a problem hiding this comment.
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
doc/api/process.md
Outdated
added: vX.X.X | ||
--> | ||
|
||
This read-only boolean tells whether the process is currently exiting. That is, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"tells whether" -> "indicates if"?
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? |
I'm + 1 on adding this and keeping the |
Or indefinitely. ;) |
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.
fc062cc
to
1b7a9bf
Compare
I've updated this with the requested changes, however, as @bnoordhuis suggested, |
@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. |
@addaleax Yeah, I'd definitely prefer to prevent user tampering, but the added overhead of having to pass an extra reference in so I'll do another PR in a bit, just adding the alias and documenting it. |
@bengl is this still work in progress? And it needs a rebase. |
Closing due to long inactivity. Please feel free to reopen if you would like to work on this again. |
This replaces the previously undocumented
_exiting
property with aread-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), orvcbuild test
(Windows) passesAffected core subsystem(s)
process