src: fix external reference list race between concurrent isolates · nodejs/node@05f4e54 · GitHub
Skip to content

Commit 05f4e54

Browse files
codebytereaduh95
authored andcommitted
src: fix external reference list race between concurrent isolates
Two threads creating their first isolate at the same time (two `CommonEnvironmentSetup`s on their own threads, or an embedder's setup racing a Worker) could corrupt or misread the external reference list handed to V8: `SnapshotBuilder::CollectExternalReferences()` creates its registry in a thread-safe function static, but then calls `external_references()` on every call, and that method appends the terminating nullptr and flips `is_finalized_` the first time through without any locking, so both threads can append, or one can read the vector while the other reallocates it. TSAN reports it for any two concurrent setups. Keep the finalized list in a second function static so finalization runs exactly once, under that static's initialization guard. Refs: #32984 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65779 Refs: #45885 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 1518b7d commit 05f4e54

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎src/node_snapshotable.cc‎

Lines changed: 3 additions & 1 deletion

‎test/cctest/test_environment.cc‎

Lines changed: 25 additions & 2 deletions

0 commit comments

Comments
 (0)