Skip to content

node:worker_threads: implement Web Locks request and query #3328

Closed

Description

@andrewtdiz

Summary

worker_threads.locks should expose Node's experimental Web Locks manager with locks.request(), locks.query(), and Lock objects. Perry currently has no visible worker_threads Web Locks implementation.

Node Behavior

A Node v25.9.0 probe shows the local lock manager shape:

const { locks } = require("node:worker_threads");

console.log(typeof locks, typeof locks.request, typeof locks.query); // object function function
const result = await locks.request("perry-probe", async (lock) => {
  console.log(lock.constructor.name, lock.name, lock.mode); // Lock perry-probe exclusive
  const snapshot = await locks.query();
  console.log(snapshot.held.map(l => `${l.name}:${l.mode}`).join(",")); // perry-probe:exclusive
  return "done";
});
console.log(result); // done
console.log((await locks.query()).held.length); // 0

Node resolves the callback result, exposes held/pending snapshots, and surfaces Lock instances with name and mode.

Perry Behavior

docs/runtime-parity-gaps.md lists worker_threads.locks; docs/runtime-parity.md lists locks.request(name[, options], callback), locks.query(), and class Lock under worker_threads Web Locks. Source search found no worker_threads locks manager, manifest entries, or tests for this surface. Exact issue/PR searches for worker_threads.locks, locks.request, locks.query, and Web Locks found no focused tracker beyond the broad parent #2507 where Web Locks were explicitly deferred.

Suggested PR Cut

Batch this with related issues in:
node:worker_threads: Web Locks parity cut

Good batch candidates:

Do not batch with:

  • unrelated modules
  • broad subsystem rewrites
  • fixes needing different test harnesses
  • MessagePort / BroadcastChannel delivery
  • Worker constructor execution
  • Worker heap/profile diagnostics

Acceptance

  • parity/regression test proves worker_threads.locks.request() grants an exclusive lock, passes a Node-shaped Lock object to the callback, and resolves to the callback return value
  • worker_threads.locks.query() exposes held and pending arrays with Node-compatible shape for covered cases
  • implementation matches Node observable behavior
  • related known-failure/docs/manifest entries updated if touched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions