-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
doc: expand documentation for process.exit() #6410
Conversation
LGTM |
'success' code `0`. | ||
* `code` {Integer} The exit code. Defaults to `0`. | ||
|
||
The `process.exit()` methods instructs Node.js to terminate the process as |
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.
Should "methods" be singular?
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.
method
LGTM with a couple comments. |
It is important to note that calling `process.exit()` will force the process to | ||
exit as quickly as possible *even if there are still asynchronous operations | ||
pending* in the event loop, *including* i/o operations to `process.stdout` and | ||
`process.stderr`. |
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.
Here's where it gets weird: those stdio
operations are actually synchronous on the node layer, sometimes full synchronous, sometimes not at an os/libuv level.
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.
Yep. Tried to capture some of those nuances in my first edit but gave up because it ended up being too confusing. Open to wording that works better.
Additional note that I'm not sure fits in: It's actually "safer" to exit the process by throwing. |
The fact that process.exit() interrupts pending async operations such as non-blocking i/o is becoming a bit more pronounced with the recent libuv update. This commit expands the documentation for `process.exit()` to explain clearly how it affects async operations.
@cjihrig @Fishrock123 ... updated to address nits |
LGTM, very good. I hope this will clarified through API rather in the future, as per linked discussions. |
Lgtm, sharing the same sentiments as @eljefedelrodeodeljefe. |
Should add a description of how to correctly flush/drain stdout/stderr if |
@kzc ... do you recommend a particular approach for that example? |
@jasnell I'd have to recommend the use of https://www.npmjs.com/package/exit Some might argue that it's less than ideal, but it was created to fill a need. People want to call |
@kzc sorry, but we cannot do this. Hints to userland packages are really rare. Also the way they do it is not advisable. Please just wait for resolutions around Since you haven't brought up an example, I would say this PR is good to merge. |
Then make an equivalent example not citing this third party user land package that drains Edit: There's a reason why |
@kzc ... my preference would be to go ahead and get this change landed as is then add an example of stdout/stderr draining later once we're a bit more settled on the right approach. Fair? |
@jasnell Cool. |
Yep. |
The fact that process.exit() interrupts pending async operations such as non-blocking i/o is becoming a bit more pronounced with the recent libuv update. This commit expands the documentation for `process.exit()` to explain clearly how it affects async operations. PR-URL: #6410 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Lindstaedt <[email protected]>
Landed in c2bbfe2 |
I just studied the implementation of the third party It only does partial stdout/stderr flushing at the best of times, and at worse it simply disables writes to stdout/stderr, and then it returns and allows program execution to continue - which can have bad consequences. Because I do not believe it is possible to fully flush any stream synchronously immediately prior to calling |
The fact that process.exit() interrupts pending async operations such as non-blocking i/o is becoming a bit more pronounced with the recent libuv update. This commit expands the documentation for `process.exit()` to explain clearly how it affects async operations. PR-URL: #6410 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Lindstaedt <[email protected]>
The fact that process.exit() interrupts pending async operations such as non-blocking i/o is becoming a bit more pronounced with the recent libuv update. This commit expands the documentation for `process.exit()` to explain clearly how it affects async operations. PR-URL: nodejs#6410 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Lindstaedt <[email protected]>
This does not land cleanly on v4.x if someone would like to manually backport let me know |
ping @jasnell |
In light of #6867 this sentence in the doc PR is incorrect:
|
Checklist
Affected core subsystem(s)
doc (process)
Description of change
The fact that process.exit() interrupts pending async operations such as non-blocking i/o is becoming a bit more pronounced with the recent libuv update. This commit expands the documentation for
process.exit()
to explain clearly how it affects async operations.