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

src: fix process exit listeners not receiving unsettled tla codes #56872

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dario-piotrowicz
Copy link
Contributor

@dario-piotrowicz dario-piotrowicz commented Feb 2, 2025

fix listeners registered via process.on('exit', ... not receiving error code 13 when an unsettled top-level-await is encountered in the code

Fixes: #53551

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Feb 2, 2025
fix listeners registered via `process.on('exit', ...` not receiving
error code 13 when an unsettled top-level-await is encountered in
the code
@dario-piotrowicz dario-piotrowicz force-pushed the dario/53551/process-on-exit-unsettled-tlas branch from eef4c1f to 80a0041 Compare February 2, 2025 00:35
Copy link

codecov bot commented Feb 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.20%. Comparing base (2bd5694) to head (549873d).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56872      +/-   ##
==========================================
+ Coverage   89.16%   89.20%   +0.03%     
==========================================
  Files         665      665              
  Lines      192602   192541      -61     
  Branches    37050    37043       -7     
==========================================
+ Hits       171732   171751      +19     
+ Misses      13678    13640      -38     
+ Partials     7192     7150      -42     
Files with missing lines Coverage Δ
src/api/embed_helpers.cc 74.61% <100.00%> (-0.02%) ⬇️
src/api/hooks.cc 84.44% <100.00%> (+0.72%) ⬆️

... and 61 files with indirect coverage changes

Copy link
Member

@joyeecheung joyeecheung left a 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.

@@ -1,2 +1,7 @@
process.on('exit', (exitCode) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you put these into separate tests? Otherwise we lose coverage of the cases where there isn't any exit handler installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 🙂

Local<Integer> exit_code_int =
Integer::New(isolate, static_cast<int32_t>(exit_code));

if (ProcessEmit(env, "exit", exit_code_int).IsEmpty()) {
Copy link
Member

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.

Copy link
Contributor Author

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:
Screenshot 2025-02-04 at 23 31 42

does it look ok? 🙏

The issue is that it's not fully working 😖

The problem is that as I get undefined in my test:
Screenshot 2025-02-04 at 23 39 14

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? 🙏

@dario-piotrowicz dario-piotrowicz force-pushed the dario/53551/process-on-exit-unsettled-tlas branch from 23428e6 to 549873d Compare February 4, 2025 21:31
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++. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect exitCode when process fails due to circular dependency of dynamic import
3 participants