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

node-api: allow napi_delete_reference in basic finalizers #55620

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

Conversation

legendecas
Copy link
Member

napi_delete_reference must be called immediately for a
napi_reference returned from napi_wrap in the corresponding
finalizer, in order to clean up the napi_reference timely.

napi_delete_reference is safe to be invoked during GC.

`napi_delete_reference` must be called immediately for a
`napi_reference` returned from `napi_wrap` in the corresponding
finalizer, in order to clean up the `napi_reference` timely.

`napi_delete_reference` is safe to be invoked during GC.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/node-api

@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. node-api Issues and PRs related to the Node-API. labels Oct 31, 2024
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.96%. Comparing base (7270f84) to head (551a7ae).
Report is 218 commits behind head on main.

Files with missing lines Patch % Lines
src/js_native_api_v8.cc 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55620      +/-   ##
==========================================
- Coverage   88.43%   87.96%   -0.47%     
==========================================
  Files         654      656       +2     
  Lines      187666   188384     +718     
  Branches    36119    35968     -151     
==========================================
- Hits       165954   165716     -238     
- Misses      14954    15838     +884     
- Partials     6758     6830      +72     
Files with missing lines Coverage Δ
src/js_native_api_v8.cc 76.51% <0.00%> (ø)

... and 158 files with indirect coverage changes

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@mhdawson mhdawson added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2024
@nodejs-github-bot
Copy link
Collaborator

@mhdawson
Copy link
Member

mhdawson commented Nov 1, 2024

@vmoroz will confirm that there is no issue in a Hermes implementation.

Main concern is around if deleting the reference and making an object collectable could cause some issues, for example if an engine uses reference counting and would try to collect the object immediately.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

Marking as request changes so we don't land until the check @vmoroz is going to do is complete

@@ -0,0 +1,20 @@
// Flags: --expose-gc
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also test that the finalizer was called? Like, adding a heap-allocated int to the environment with napi_set_instance_data which is incremented from the finalizer, and an accessor to ensure that the value was incremented. We should try to make sure, if possible, that we check after gc but before the event loop has had a chance to run. That way we can distinguish between synchronous and asynchronous finalization.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, thanks!

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. node-api Issues and PRs related to the Node-API.
Projects
Development

Successfully merging this pull request may close these issues.

4 participants