-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
module: process.exit() should result in exit code 0
#41388
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
Changes from all commits
b828eac
5ebf9b0
fab1eed
4e6f2c0
dbf136c
24bc42c
adcf374
73e0b71
d58b5b9
d7bb21f
0951516
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| // Handle a Promise from running code that potentially does Top-Level Await. | ||
| // In that case, it makes sense to set the exit code to a specific non-zero | ||
| // value if the main code never finishes running. | ||
| function handleProcessExit() { | ||
| process.exitCode ??= 13; | ||
| } | ||
|
|
||
| module.exports = { | ||
| handleProcessExit, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,10 @@ const { | |
| } = require('internal/validators'); | ||
| const constants = internalBinding('constants').os.signals; | ||
|
|
||
| const { | ||
| handleProcessExit, | ||
| } = require('internal/modules/esm/handle_process_exit'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this logic happens for all code, not just ESM code, should
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It only happens for ESM code, because it's the only place we have TLA in Node.js.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious what's the full name of TLA? 🤣
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an acronym for Top Level Await, sorry I was too lazy to type it all out 🙈 |
||
|
|
||
| const kInternal = Symbol('internal properties'); | ||
|
|
||
| function assert(x, msg) { | ||
|
|
@@ -175,6 +179,8 @@ function wrapProcessMethods(binding) { | |
| memoryUsage.rss = rss; | ||
|
|
||
| function exit(code) { | ||
| process.off('exit', handleProcessExit); | ||
|
|
||
| if (code || code === 0) | ||
| process.exitCode = code; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| process.exit(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Worker, isMainThread } from 'worker_threads'; | ||
|
|
||
| if (isMainThread) { | ||
| new Worker(new URL(import.meta.url)); | ||
| await new Promise(() => {}); | ||
| } else { | ||
| process.exit(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.