-
Notifications
You must be signed in to change notification settings - Fork 29.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
n-api: ensure scope present for finalization #33508
Conversation
9642cc5
to
6a62c2a
Compare
@addaleax, @gabrielschulhof hoping you can confirm if you think this adds the scope in the right place. While investigating I checked that the status of the env when the assert is hit indicates that we can still call back to JS, which I'm assuming confirms it's ok to have a Scope/allocation. I could see moving the scope out of the loop to reduce overhead, but left it in the loop as that seems safer in terms of memory use. |
We could create a version of
Lines 57 to 65 in 9949a2e
In TSFN's Lines 303 to 313 in 9949a2e
The same is true in TSFN's Lines 318 to 324 in 9949a2e
In Lines 458 to 460 in 9949a2e
In Lines 858 to 871 in 9949a2e
This is the one you want to change. Would it be expensive if we declared both a Lines 270 to 276 in 9949a2e
In Lines 478 to 480 in 9949a2e
|
So, if we can agree in the two places that we can replace with/add a |
@gabrielschulhof Just to be explicit here, |
@gabrielschulhof once #33570 lands, I'll update this PR to add CallIntoModuleWithScopes and use it in all places except for napi_module_register_by_symbol and validate that the new test fails without the scopes/passes with them. |
@mhdawson it must also not be used in |
Codecov Report
@@ Coverage Diff @@
## master #33508 +/- ##
==========================================
- Coverage 96.77% 96.77% -0.01%
==========================================
Files 202 201 -1
Lines 67129 66642 -487
==========================================
- Hits 64966 64492 -474
+ Misses 2163 2150 -13
Continue to review full report at Codecov.
|
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com>
@gabrielschulhof I spent some time looking at a common CallIntoModuleWithScopes, however, that required passing in the AsyncResource which is not available at the place I'm trying to fix and due to need for a HandleScope outside of the callInfoModule or not having a CallbackScope only 2 of the other CallIntoModule locations would have used the new method. I think based only something like only 25% of the paths being able to use it, its not worth adding the new function and simply added the HandleScope to the path from which it was missing. |
Think this is now ready to go. Ran the new test with node_g and still passed after the latest change so should be good to go. |
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.
LGTM
I nevertheless think we can streamline our use of scopes, but that's beyond the scope purview of this PR 🙂
Resume build: https://ci.nodejs.org/job/node-test-pull-request/31772/ |
Resume build: https://ci.nodejs.org/job/node-test-pull-request/31804/ |
New build since that seems to be what's needed: https://ci.nodejs.org/job/node-test-pull-request/31807/ |
Clean CI run landing. |
The last build was yellow. I think this can land. |
Landed in 362e4a1 |
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: #33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: nodejs#33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: #33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: #33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: nodejs#33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: #33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/node-addon-api#722 Ensure a scope is on stack during finalization as finalization functions can create JS Objects Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com> PR-URL: #33508 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Spent some time looking at nodejs/node-addon-api#729 which was related to a crash during finalization when using node-addon-api ObjectWrap.
I think it should be fixed in core as opposed to node-addon-api as it should be possible to hit the same problem using N-API directly instead of node-addon-api.
It seems to be more subtle than the scope never being in place. The added is the simplest test that causes the problem to recreate when run under debug and without the change adding the scope.
Refs: nodejs/node-addon-api#722
Ensure a scope is on stack during finalization
as finalization functions can create JS Objects
Signed-off-by: Michael Dawson michael_dawson@ca.ibm.com
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes