fix(scripting/node): remove premature Stop() call before FreeEnvironment()#3854
Open
gtolontop wants to merge 1 commit intocitizenfx:masterfrom
Open
fix(scripting/node): remove premature Stop() call before FreeEnvironment()#3854gtolontop wants to merge 1 commit intocitizenfx:masterfrom
gtolontop wants to merge 1 commit intocitizenfx:masterfrom
Conversation
…ent() node::Stop() calls isolate_->TerminateExecution() which terminates the main isolate while worker threads are still entered on it. FreeEnvironment() already handles the full shutdown sequence including stop_sub_worker_contexts(), RunCleanup(), and RunAtExit(), making the Stop() call both redundant and harmful.
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.
Goal of this PR
Fix a server crash (
FATAL ERROR: v8::Isolate::Dispose() Disposing the isolate that is entered by a thread) when a Node 22 worker thread is terminated or when a script using workers is stopped.How is this PR achieving the goal
The
Destroy()shutdown sequence callednode::Stop(m_nodeEnvironment)right beforenode::FreeEnvironment(m_nodeEnvironment). This is problematic because:node::Stop()callsisolate_->TerminateExecution(), which sets a V8 termination flag on the isolatenode::FreeEnvironment()then callsstop_sub_worker_contexts(), which tries toExit()andJoinThread()each workerThe fix removes the
node::Stop()call.node::FreeEnvironment()already handles the full shutdown sequence: it setsstopping = true, setscan_call_into_js = false, stops and joins sub-workers, runs cleanup hooks, runs AtExit hooks, and deletes the environment. This matches Node.js's ownCommonEnvironmentSetupdestructor which does not callStop()beforeFreeEnvironment().This PR applies to the following area(s)
FiveM and RedM Node.js scripting runtime (
citizen-scripting-node)Successfully tested on
worker.terminate()no longer crashesChecklist
Fixes issues
Fixes #3846