All problems

Stale Owner Releases a Job Lease

Level 3 · node · Concurrency · Lease ownership error

Scenario

Multiple workers use a lease containing an ownerId to prevent duplicate processing of the same background job. After a lease expires, another worker may take over the job, but operations occasionally observes that the new worker loses the same job again immediately after takeover. The worker, lease service, and lease repository are separated, and tests inject time directly.

Requirements

- A worker can acquire a job that has no lease - Another worker is rejected while a valid lease exists - After expiry, another worker can acquire the lease with a new ownerId - A previous owner finishing late must not release the current owner's lease - When the current owner finishes, its own lease is released normally

Acceptance criteria

  • The first worker acquires an unleased job
  • Another worker is rejected while the lease is valid
  • After expiry, another worker can acquire the lease as the new owner
  • A late release from the expired previous owner keeps the current owner lease intact
  • A release from the current owner removes the lease normally