Repository navigation
fix(ext/napi): pass valid env to tsfn call_js_cb after close race - #32957
Merged
Merged
Conversation
When a NAPI threadsafe function is released while calls are still pending, there is a race where TsFn::drop runs before a queued call is processed. Previously, the call_js_cb was invoked with env=NULL in this case, causing native addons like node-pty to SIGSEGV when they dereference env without a null check (crash at address 0x90). Fix: capture the env pointer in the call closure so it remains available after the TsFn is freed. The env is always valid because it is leaked via Box::into_raw in op_napi_open and never freed. V8 is also alive since the callback runs on the V8 thread. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add test_tsfn_abort_race that exercises the same close-race scenario as test_tsfn_close_race but using napi_tsfn_abort mode. Abort forces immediate close regardless of thread_count, which is another path to the is_closed=true state that previously passed null env. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TsFn::dropcan run before a queued call is processed. Previously, thecall_js_cbwas invoked withenv=NULL, crashing addons that dereference env without a null check (SIGSEGV at address 0x90)Box::into_raw, never freed) and V8 is alive (callback runs on V8 thread)test_tsfn_close_racethat spawns concurrent calling/releasing threads to exercise the raceTowards #32846