Commit Graph
2 Commits
Author SHA1 Message Date
Chengzhong Wu e97c75e154 node-api: fix crash on TSFN finalization reentrance at shutdown
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/65967
Fixes: https://github.com/nodejs/node/issues/65100
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
2026-10-31 19:25:47 +00:00
Mika FischerandGabriel Schulhof bff6ea49b8 node-api: fix data race and use-after-free in napi_threadsafe_function
Other threads can still hold a valid handle to the tsfn after
finalization if finalization was triggered by
- release with napi_tsfn_abort, or
- environment shutdown

Handle this by:
- protecting finalization itself with the mutex
- if necessary, delay deletion after finalization to when thread_count
  drops to 0
- releasing all resources as soon as possible before deletion

Fixes: https://github.com/nodejs/node/issues/55706
PR-URL: https://github.com/nodejs/node/pull/55877
Co-Authored-By: Gabriel Schulhof <gabrielschulhof@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-11-27 11:30:06 +00:00