| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
|
We could create a version of CallIntoModule and CallIntoModuleThrow that declares these scopes, because currently invocations of CallIntoModule and CallIntoModuleThrow are almost always preceded by scope declarations: FinalizeBufferCallback precedes the call into the addon with a HandleScope and a ContextScope. @addaleax can we replace the ContextScope with a CallbackScope for consistency with other calls into the addon? Lines 57 to 65 in 9949a2e In TSFN's DispatchOne we already precede the invocation of CallIntoModule with a HandleScope and a CallbackScope: Lines 303 to 313 in 9949a2e The same is true in TSFN's Finalize: Lines 318 to 324 in 9949a2e In napi_module_register_by_symbol we definitely don't need any scopes because we know the call is coming from JS: Lines 458 to 460 in 9949a2e In AfterThreadPoolWork we already precede the invocation with a declaration of HandleScope and CallbackScope. Lines 858 to 871 in 9949a2e This is the one you want to change. Would it be expensive if we declared both a HandleScope and a CallbackScope, thereby making it consistent with the other invocations where we need both? Lines 270 to 276 in 9949a2e In InvokeCallback we definitely don't need any scopes because we know the call is coming from JS: Lines 478 to 480 in 9949a2e |
Sorry, something went wrong.
|
So, if we can agree in the two places that we can replace with/add a CallbackScope before the invocation, then we can add a method to napi_env called CallIntoModuleWithScopes that declares them and use that method everywhere. |
Sorry, something went wrong.
|
@gabrielschulhof Just to be explicit here, CallbackScope is for asynchronous operations – Finalizers could definitely fall under that, yes. |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
|
@mhdawson it must also not be used in InvokeCallback because control is coming from JS there (last one on the list above). |
Sorry, something went wrong.
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.
|
Sorry, something went wrong.
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. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
I nevertheless think we can streamline our use of scopes, but that's beyond the scope purview of this PR 🙂
Sorry, something went wrong.
|
Resume build: https://ci.nodejs.org/job/node-test-pull-request/31772/ |
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
|
Resume build: https://ci.nodejs.org/job/node-test-pull-request/31804/ |
Sorry, something went wrong.
Sorry, something went wrong.
|
New build since that seems to be what's needed: https://ci.nodejs.org/job/node-test-pull-request/31807/ |
Sorry, something went wrong.
|
Clean CI run landing. |
Sorry, something went wrong.
|
The last build was yellow. I think this can land. |
Sorry, something went wrong.
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>
| Back | FazBrowse Home | New Git URL |
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