node-api: enter env context for async callbacks · nodejs/node@875c7ec · GitHub
Skip to content

Commit 875c7ec

Browse files
codebytereaduh95
authored andcommitted
node-api: enter env context for async callbacks
`uvimpl::Work::AfterThreadPoolWork()` and the thread-safe function's `DispatchOne()` and `Finalize()` opened an `AsyncResource::CallbackScope` with only a `HandleScope`. `InternalCallbackScope` expects the resource's environment context to be entered and otherwise asserts that `Environment::GetCurrent(isolate)` is that environment, so with two environments on one isolate an addon's async work completion or thread-safe function call aborted the process whenever the other environment's context was current when the loop ran the callback. Enter the node-api env's context first, as `CallFinalizer()` and the zlib and WebCrypto thread pool callbacks already do. In `Finalize()` the scope covers only the finalizer call, since `MaybeDelete()` can free the env whose persistent handle `context()` returns. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65406 Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 069a1b1 commit 875c7ec

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

‎src/node_api.cc‎

Lines changed: 3 additions & 0 deletions

‎test/cctest/test_node_api.cc‎

Lines changed: 106 additions & 0 deletions

0 commit comments

Comments
 (0)