Skip to content

src: fix Web Locks synchronization across workers - #67608

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:web-locks-fix-worker-sync
Open

ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:web-locks-fix-worker-sync

Conversation

@ShogunPanda

Copy link
Copy Markdown
Contributor

Web Locks keeps process-wide state shared by every Environment, but the stealing, granting and cleanup code settles per-environment V8 objects and updates that state without respecting isolate ownership or the documented guarantees.

This change:

  • settles locks stolen with { steal: true } in their owning environment instead of from the stealing thread;
  • makes the grantability decision and the insertion of the granted lock a single critical section, so that two environments can no longer hold the same exclusive lock;
  • keeps an environment alive while it has pending requests and cancels the native request when it is aborted;
  • wakes eligible waiters after the locks of an exiting environment are cleaned up.

New worker tests cover cross-environment stealing, lifecycle, cancellation and exclusive lock atomicity.

This touches the same area as #67305; I'm happy to rebase on top of it or the other way around, whichever lands first.

AI-assisted work. All changes reviewed by a human.

Settle stolen locks in their owning environment instead of from the
stealing thread, make the grant decision and the insertion into the held
locks a single critical section, keep the environment alive while it has
pending requests, cancel native requests on abort, and wake eligible
waiters after an owner is cleaned up. Add worker regression tests.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. locks Issues and PRs related to the Web Locks API. needs-ci PRs that need a full CI run. labels Nov 19, 2026
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.59322% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (d9e18d5) to head (182ccad).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/node_locks.cc 85.58% 5 Missing and 11 partials ⚠️
lib/internal/locks.js 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67608      +/-   ##
==========================================
- Coverage   90.72%   90.72%   -0.01%     
==========================================
  Files         801      801              
  Lines      280809   280858      +49     
  Branches    54212    54215       +3     
==========================================
+ Hits       254776   254819      +43     
- Misses      16209    16217       +8     
+ Partials     9824     9822       -2     
Files with missing lines Coverage Δ
src/node_locks.h 88.23% <ø> (ø)
lib/internal/locks.js 95.34% <85.71%> (+0.95%) ⬆️
src/node_locks.cc 81.85% <85.58%> (+6.70%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fatihguzeldev

Copy link
Copy Markdown
Contributor

hey paolo, can we land #67305 first and rebase this on top? i opened it for #67216 and added the suggested rollback.

also, the steal and abort fixes make sense to me. i'm less sure about keeping workers alive while they wait for a lock. i'd like to discuss that separately and document what we decide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. locks Issues and PRs related to the Web Locks API. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants