Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node24-fsevents-worker-threads-abort

Minimal reproduction for a SIGABRT crash (Abort trap: 6) that happens when a native N-API addon that uses a napi threadsafe function (here: fsevents) is loaded and used inside a worker_threads Worker, and that worker exits while the threadsafe function is still active.

This reproduces starting with Node.js v24.15.0 (and every 24.x version tested since, up to v24.19.0). It does not reproduce on Node.js v24.11.0 or v24.11.1.

This was originally discovered as a crash inside a large Next.js 16.3.0 monorepo build (next build --turbopack), where Next's build workers (worker_threads) load fsevents transitively (via chokidar/watchpack, pulled in for file watching) and exit shortly after doing their work. The crash is 100% consistent across dozens of real crash reports collected via macOS's crash reporter (~/Library/Logs/DiagnosticReports/node-*.ips), and this repro isolates it down to pure Node.js + fsevents, with no Next.js or Turbopack involved at all.

Crash signature

Every crash (both in the real Next.js build and in this isolated repro) has the identical stack trace on the aborting WorkerThread:

__pthread_kill
pthread_kill
abort
uv_mutex_lock
napi_release_threadsafe_function
fse_instance_destroy
napi_env__::CallIntoModule<...>
node_napi_env__::CallFinalizer(...)
v8impl::Reference::Finalize()
node_napi_env__::DeleteMe()
node::Environment::CloseHandle<...>
uv_run
node::Environment::RunCleanup()
node::FreeEnvironment(node::Environment*)
node::worker::Worker::Run()
node::worker::Worker::StartThread(...)::$_0::__invoke(void*)
_pthread_start
thread_start

i.e. during worker-thread environment teardown, napi_release_threadsafe_function tries to acquire a mutex (uv_mutex_lock) while cleaning up fsevents' native threadsafe function, and this ends in an abort().

Environment

  • OS: macOS 15.6.1 (24G90), Apple Silicon (arm64)
  • Node.js: reproduces on v24.15.0, v24.16.0, v24.19.0 — does not reproduce on v24.11.0 / v24.11.1
  • fsevents: 2.3.3

How to reproduce

npm install   # or: copy a prebuilt fsevents/ into node_modules if node-gyp
              # has trouble building fsevents on your toolchain
node main.mjs 50

Expected

All 50 worker threads start, watch a directory with fsevents, and exit cleanly (worker N exited with code 0), ending with:

done, no crash across 50 workers

This is what happens on Node.js v24.11.0.

Actual

The process aborts on the very first worker with exit code 134 (SIGABRT), before any worker N exited log line is even printed, since the native abort takes down the entire process (all threads share one OS process).

$ node main.mjs 50
Abort trap: 6
$ echo $?
134

This is what happens on Node.js v24.15.0 through at least v24.19.0.

Files

  • worker.mjs — the code that runs inside each worker_threads Worker. It require()s fsevents, starts a watch on a temp directory, and exits the worker (process.exit(0)) shortly after — without explicitly stopping the watcher first.
  • main.mjs — spawns N worker threads sequentially (each running worker.mjs) and waits for each to exit.

Notes / theory

This looks like a race condition in Node's N-API cleanup path for napi_threadsafe_function during worker-thread teardown: if the threadsafe function still has in-flight/queued work (as fsevents' native watcher does) when the worker's Environment starts running cleanup handlers, the finalizer path ends in a deadlock/mutex-lock failure that triggers abort() rather than failing gracefully.

Because this only manifests when a native addon has a "live" threadsafe function at worker-exit time, it does not reproduce in trivial addon-free worker_threads usage, and it does not reproduce in a bare create-next-app-generated project (which doesn't happen to load fsevents inside its build workers) — only in projects (like the original large monorepo this was found in) where a native addon such as fsevents ends up loaded and active inside worker threads that exit.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages