Skip to content

node-api: add nested object wrap and napi_ref test #57981

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

Merged
merged 2 commits into from
Apr 25, 2025

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Apr 22, 2025

Test that an napi_ref can be nested inside another ObjectWrap. The test
shows a critical case where a finalizer deletes an napi_ref whose
finalizer is also scheduled.

This add a test for comments at:

node/src/node_api.cc

Lines 116 to 118 in 68cc1c9

// As userland code can delete additional references in one finalizer,
// the list of pending finalizers may be mutated as we execute them, so
// we keep iterating it until it is empty.

The changes in test/js-native-api/6_object_wrap/myobject.cc are auto-formatted by make format-cpp as the file is renamed.

Refs: #57861 (review)

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Apr 22, 2025

Review requested:

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

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests. labels Apr 22, 2025
@legendecas legendecas force-pushed the node-api/nested-wrap branch 2 times, most recently from 8fdaaaa to a5aa845 Compare April 22, 2025 22:47
Test that an napi_ref can be nested inside another ObjectWrap. The test
shows a critical case where a finalizer deletes an `napi_ref` whose
finalizer is also scheduled.
@legendecas legendecas force-pushed the node-api/nested-wrap branch from a5aa845 to 161b8e3 Compare April 22, 2025 22:48
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.27%. Comparing base (e9b286c) to head (21ac07e).
Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57981      +/-   ##
==========================================
- Coverage   90.27%   90.27%   -0.01%     
==========================================
  Files         630      630              
  Lines      186165   186158       -7     
  Branches    36485    36475      -10     
==========================================
- Hits       168064   168049      -15     
- Misses      10974    10979       +5     
- Partials     7127     7130       +3     

see 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vmoroz
Copy link
Member

vmoroz commented Apr 23, 2025

@legendecas , in regards to the PR #57861, do we ever have a situation when a napi_ref is removed from the finalizer queue, or added to it twice? I guess, in such cases the batched processing of the queue may not work.

@Thhe1oldlady

This comment was marked as duplicate.

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 Apr 23, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 23, 2025
@nodejs-github-bot
Copy link
Collaborator

@legendecas
Copy link
Member Author

@vmoroz in regards to the PR #57861, do we ever have a situation when a napi_ref is removed from the finalizer queue, or added to it twice? I guess, in such cases the batched processing of the queue may not work.

I think node_api_post_finalizer is the only node-api that allows putting a finalizer into the back of the queue, and it is how it supposed to work.

Putting a single finalizer into the queue twice is a bug. Do you have a minimum test to reproduce it?

@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 24, 2025
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Apr 24, 2025

This comment was marked as outdated.

@legendecas legendecas removed the request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. label Apr 25, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

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 moved this from Need Triage to In Progress in Node-API Team Project Apr 25, 2025
@vmoroz
Copy link
Member

vmoroz commented Apr 25, 2025

@vmoroz in regards to the PR #57861, do we ever have a situation when a napi_ref is removed from the finalizer queue, or added to it twice? I guess, in such cases the batched processing of the queue may not work.

I think node_api_post_finalizer is the only node-api that allows putting a finalizer into the back of the queue, and it is how it supposed to work.

Putting a single finalizer into the queue twice is a bug. Do you have a minimum test to reproduce it?

@legendecas , no, I do not have a repro. I am just trying to understand if the PR #57861 has issues or not. Currently based on your answers, I tend to believe that it does not have issues. I wonder if you already saw any issues by running that PR against these new tests.

@legendecas
Copy link
Member Author

@vmoroz I commented at #57861 (comment). The change in that PR crashes this new test.

@legendecas legendecas added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 25, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 25, 2025
@nodejs-github-bot nodejs-github-bot merged commit 3b90f34 into nodejs:main Apr 25, 2025
60 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 3b90f34

@github-project-automation github-project-automation bot moved this from In Progress to Done in Node-API Team Project Apr 25, 2025
@legendecas legendecas deleted the node-api/nested-wrap branch April 25, 2025 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests.
Projects
Development

Successfully merging this pull request may close these issues.

5 participants