Skip to content

src: wake pending web locks when workers exit - #67305

Open
fatihguzeldev wants to merge 2 commits into
nodejs:mainfrom
fatihguzeldev:web-locks-worker-exit
Open

fatihguzeldev wants to merge 2 commits into
nodejs:mainfrom
fatihguzeldev:web-locks-worker-exit

Conversation

@fatihguzeldev

Copy link
Copy Markdown
Contributor

when a worker exits, its locks are removed but other requests can stay
pending until another lock request processes the queue.

wake remaining waiters during cleanup. reserve granted locks under the
queue mutex to prevent concurrent exclusive grants, and protect target
environments while queuing wakeups.

Fixes: #67216

wake requests left pending after worker cleanup. register granted locks
under the queue mutex to prevent concurrent exclusive grants, and
keep target environments alive until wakeups are queued.

add regression tests for worker exits and exclusive lock ownership.

Fixes: nodejs#67216
Signed-off-by: Fatih Güzel <fatihguzeldev@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 6, 2026
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.59574% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.74%. Comparing base (9d8a9ad) to head (27042d3).
⚠️ Report is 239 commits behind head on main.

Files with missing lines Patch % Lines
src/node_locks.cc 76.59% 5 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67305      +/-   ##
==========================================
+ Coverage   90.69%   90.74%   +0.05%     
==========================================
  Files         797      801       +4     
  Lines      279612   280992    +1380     
  Branches    53789    54271     +482     
==========================================
+ Hits       253584   254980    +1396     
+ Misses      16298    16186     -112     
- Partials     9730     9826      +96     
Files with missing lines Coverage Δ
src/node_locks.cc 76.99% <76.59%> (+1.84%) ⬆️

... and 224 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.

Comment thread src/node_locks.cc
pending_queue_.erase(queue_iter);
if (!grantable_request->steal()) {
// Reserve the lock before another Environment can process the queue.
granted_lock = grant_lock(*grantable_request);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since granted_lock is now inserted into held_locks_ up front here (and on line 461 for steal), any early return below before the settlement handlers run or are attached (e.g. CreateLockInfoObject failing, callback->Call(...) throwing synchronously, or promise->Then(...) failing) will leave granted_lock stuck in held_locks_ for as long as env stays alive and permanently block that lock name.

Could we guard granted_lock with an OnScopeLeave rollback that removes it from held_locks_ unless the handler attachment / synchronous release succeeds?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, rudolf. i added the rollback and a regression test.

release the reserved lock if the callback throws or its settlement
handlers cannot be attached. wake waiters and resume queue processing
so other ready requests can proceed.

Signed-off-by: Fatih Güzel <fatihguzeldev@gmail.com>
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++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web Locks: a request waiting for a lock stays pending after the worker thread holding the lock exits

3 participants