-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
src: fix process exit listeners not receiving unsettled tla codes #56872
base: main
Are you sure you want to change the base?
src: fix process exit listeners not receiving unsettled tla codes #56872
Conversation
eef4c1f
to
80a0041
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #56872 +/- ##
=======================================
Coverage 89.13% 89.14%
=======================================
Files 665 665
Lines 193167 193190 +23
Branches 37190 37191 +1
=======================================
+ Hits 172185 172210 +25
- Misses 13731 13738 +7
+ Partials 7251 7242 -9
|
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.
Thanks for the PR. Some comments about the approaches taken.
Local<Integer> exit_code_int = | ||
Integer::New(isolate, static_cast<int32_t>(exit_code)); | ||
|
||
if (ProcessEmit(env, "exit", exit_code_int).IsEmpty()) { |
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 think prior to emitting the event, it should also set the kHasExitCode
and kExitCode
fields in the exit info buffer (basically needing an implementation of Environment::set_exit_code()
that is the counter part of Environment::exit_code
) so that in the handler, process.exitCode
would be 13, to be consistent with other paths. Also in any case, the documentation of the exit
event in doc/api/process.md
should also be updated to note this extra source of exit 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.
Hey @joyeecheung 👋
I've been trying to implement what you suggested and I created this set_exit_code
method:
does it look ok? 🙏
The issue is that it's not fully working 😖
The problem is that as I get undefined
in my test:
But I am sure that env->set_exit_code()
is working since if I use it when process
already has an exitCode
then I can actually see the exit code changing, the issue is that when there is no exit code already set this doesn't seem to set it 😕 (this makes me suspect that I'm doing something wrong with kHasExitCode
... but I don't think I am?)
do you have any idea what might be going wrong? 🙏
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.
Oh I mean you'll need to set the exit code when it's updated to ExitCode::kUnsettledTopLevelAwait before you invoke process.emit, implementing that helper alone would get it called.
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.
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.
The env->set_exit_code()
should only be necessary in the branch where you reassign exit_code to ExitCode::kUnsettledTopLevelAwait
, since it's otherwise unchanged.
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.
ok good point, but either way it's not working 😓
I've been trying to debug this but I could not yet figure our why process.exitCode
is not getting set by this 😓
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.
oof... I think I've missed something really obvious! 🤦
updating the exit_info_
values is not sufficient, since the getter for process.exitCode
is this:
node/lib/internal/bootstrap/node.js
Lines 110 to 112 in d1f8ccb
get() { | |
return exitCode; | |
}, |
which relies on this local variable:
node/lib/internal/bootstrap/node.js
Line 107 in d1f8ccb
let exitCode; |
which is set in the setter and which is unrelated to exit_info_
😕
right?
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.
@joyeecheung it took me ages to solve this super silly thing, but I think I got it 😅 (I was so focused on the c++ side of things that missed to look deeper in the lib js code 😓)
I also updated the docs as you very sensibly suggested
Please have another look when you've got a sec 🙂 🙏
23428e6
to
549873d
Compare
fix listeners registered via `process.on('exit', ...` not receiving error code 13 when an unsettled top-level-await is encountered in the code
a717cb0
to
b456e86
Compare
fix listeners registered via `process.on('exit', ...` not receiving error code 13 when an unsettled top-level-await is encountered in the code
b456e86
to
7a48cfd
Compare
fix listeners registered via
process.on('exit', ...
not receiving error code 13 when an unsettled top-level-await is encountered in the codeFixes: #53551