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: restore ability to run under NAPI_EXPERIMENTAL #1409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gabrielschulhof
Copy link
Contributor

Since we made the default for Node.js core finalizers synchronous for users running with NAPI_EXPERIMENTAL and introduced env->CheckGCAccess() in Node.js core, we must now defer all finalizers in node-addon-api, because our users likely make non-gc-safe Node-API calls from existing finalizers. To that end,

  • Use the NAPI_VERSION environment variable to detect whether NAPI_EXPERIMENTAL should be on, and add it to the defines if NAPI_VERSION is set to NAPI_VERSION_EXPERIMENTAL, i.e. 2147483647.
  • When building with NAPI_EXPERIMENTAL,
    • render all finalizers asynchronous, and
    • expect napi_cannot_run_js instead of napi_exception_pending.

@mhdawson
Copy link
Member

I might have been thinking of another change but I thought we had made it opt-in with another define? @legendecas is that right?

@legendecas
Copy link
Member

because our users likely make non-gc-safe Node-API calls from existing finalizers

I'm afraid that I didn't understand this assumption. Is this assumption unique to node-addon-api, not the node-api c layer?

@gabrielschulhof gabrielschulhof force-pushed the restore-ability-to-run-with-NAPI_EXPERIMENTAL branch 2 times, most recently from 8f78a76 to 8b19089 Compare January 26, 2024 07:23
@gabrielschulhof gabrielschulhof force-pushed the restore-ability-to-run-with-NAPI_EXPERIMENTAL branch from 8b19089 to 2c5853a Compare February 18, 2024 18:05
Since we made the default for Node.js core finalizers synchronous for
users running with `NAPI_EXPERIMENTAL` and introduced
`env->CheckGCAccess()` in Node.js core, we must now defer all
finalizers in node-addon-api, because our users likely make non-gc-safe
Node-API calls from existing finalizers. To that end,
  * Use the NAPI_VERSION environment variable to detect whether
    `NAPI_EXPERIMENTAL` should be on, and add it to the defines if
    `NAPI_VERSION` is set to `NAPI_VERSION_EXPERIMENTAL`, i.e.
    2147483647.
  * When building with `NAPI_EXPERIMENTAL`,
    * render all finalizers asynchronous, and
    * expect `napi_cannot_run_js` instead of `napi_exception_pending`.
@gabrielschulhof
Copy link
Contributor Author

Core status of needed changes:

branch backport complete released
v22.x ✅ (v22.0.0)
v20.x (> v20.12.2)
v18.x

@KevinEady
Copy link
Contributor

Hi @gabrielschulhof ,

Looks like this is becoming of more importance. I can take a look at continuing this work? Judging by the latest CI failure, looks like the Napi::External<> object needs to implement a similar approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants