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

Native addon use ThreadsafeFunction in multithreads env casue EXC_BAD_ACCESS in worker_threads in Node 18 #56432

Open
Brooooooklyn opened this issue Jan 2, 2025 · 1 comment
Assignees
Labels
node-api Issues and PRs related to the Node-API.

Comments

@Brooooooklyn
Copy link

Brooooooklyn commented Jan 2, 2025

Version

v18.20.5

The Node 20, Node 22 works fine

What steps will reproduce the bug?

The minimal reproduce example is very difficult to construct; if anyone is interested, they can check how to reproduce in the Rust project:

  1. Clone https://github.com/napi-rs/napi-rs
  2. Checkout to 12-23-feat_napi_impl_readablestream_and_asyncgenerator branch
  3. Install latest stable Rust, it's 1.83.0 at this moment
  4. corepack enable
  5. yarn install
  6. yarn workspace @examples/napi build
  • if you want to run test directly yarn workspace @examples/napi test __tests__/stream.spec.ts
  • if you want to run lldb
    • cd examples/napi
    • lldb node
    • run --loader ts-node/esm/transpile-only ../../node_modules/ava/entrypoints/cli.mjs __tests__/stream.spec.ts

lldb log:

lldb) bt
* thread #13, stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x00000001000803dc node`napi_env__::DeleteMe() + 52
    frame #1: 0x000000010008373c node`v8impl::(anonymous namespace)::ThreadSafeFunction::~ThreadSafeFunction() + 84
    frame #2: 0x0000000100083784 node`v8impl::(anonymous namespace)::ThreadSafeFunction::~ThreadSafeFunction() + 12
    frame #3: 0x0000000100083980 node`void node::Environment::CloseHandle<uv_handle_s, v8impl::(anonymous namespace)::ThreadSafeFunction::CloseHandlesAndMaybeDelete(bool)::'lambda'(uv_handle_s*)>(uv_handle_s*, v8impl::(anonymous namespace)::ThreadSafeFunction::CloseHandlesAndMaybeDelete(bool)::'lambda'(uv_handle_s*))::'lambda'(uv_handle_s*)::__invoke(uv_handle_s*) + 240
    frame #4: 0x000000010244a280 libuv.1.dylib`uv_run + 520
    frame #5: 0x000000010005f58c node`node::Environment::CleanupHandles() + 252
    frame #6: 0x000000010005fbb8 node`node::Environment::RunCleanup() + 372
    frame #7: 0x000000010000beb0 node`node::FreeEnvironment(node::Environment*) + 120
    frame #8: 0x000000010014371c node`node::OnScopeLeaveImpl<node::worker::Worker::Run()::$_0>::~OnScopeLeaveImpl() + 112
    frame #9: 0x0000000100143390 node`node::worker::Worker::Run() + 1408
    frame #10: 0x0000000100145b60 node`node::worker::Worker::StartThread(v8::FunctionCallbackInfo<v8::Value> const&)::$_0::__invoke(void*) + 56
    frame #11: 0x000000018afe02e4 libsystem_pthread.dylib`_pthread_start + 136

How often does it reproduce? Is there a required condition?

Very easy to reproduce.

What is the expected behavior? Why is that the expected behavior?

Process exit with normal exit code

What do you see instead?

After some bisects, I found the latest properly Node 18 is 18.18.2, in the v18.18.2..v18.19.0 diff, I think this PR is most likely to cause this issue #42651.

Additional information

No response

@legendecas legendecas added the node-api Issues and PRs related to the Node-API. label Jan 3, 2025
@mhdawson
Copy link
Member

mhdawson commented Jan 3, 2025

@vmoroz will take a look.

@mhdawson mhdawson moved this from Need Triage to In Progress in Node-API Team Project Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node-api Issues and PRs related to the Node-API.
Projects
Status: In Progress
Development

No branches or pull requests

4 participants