Repository navigation
fix(lock): honour a negative acquire timeout with an unbounded deadline - #14521
Conversation
fix(lock): honor negative acquire timeout as wait-forever
File and Distributed keep their original retry loop and take INF as the deadline, instead of branching on a null one. The non-coroutine Mutex and Semaphore waits say why they never end.
The coroutine and uncontended cases passed before the fix, and the Redis case belongs to the e2e tier. The file lock test now reaps its child like its neighbours.
|
Review complete. No issues found. The change adds an indefinite-wait mode to the lock package: when Reviewed commit: 55ec660 |
Outside a coroutine nothing else runs to release an in-process lock, so waiting on a negative timeout could only hang. A held Mutex or Semaphore returns false at once there again, and the Lock contract says so.
🔵 Tier A · Mergeable after minor fixes
This PR makes negative timeouts wait without a deadline in the File and Distributed lock adapters, while preserving immediate failure when a synchronous Mutex or Semaphore is held. It clarifies that distinction in the Lock contract and changelog, and adds a fork-based File regression test that verifies acquisition after the holder releases. Latest changes: The latest commits clarify the synchronous Mutex/Semaphore exception in the Lock contract and narrow the changelog entry to File and Distributed.
Fix with agent prompt### Issue 1
packages/lock/src/Distributed.php:67
**Add negative-timeout coverage for Distributed**
The new regression test covers only `File`; the Redis E2E suite already tests contention and finite timeouts but never exercises `acquire(-1.0)`, so CI can miss a regression in this changed adapter. Please add a held-lock case that becomes available before the negative-timeout acquire returns.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 5
⏳ Still open from earlier reviews · 1
Merged |
| } | ||
|
|
||
| $deadline = microtime(true) + $timeout; | ||
| $deadline = $timeout < 0.0 ? INF : microtime(true) + $timeout; |
There was a problem hiding this comment.
Add negative-timeout coverage for Distributed
The new regression test covers only File; the Redis E2E suite already tests contention and finite timeouts but never exercises acquire(-1.0), so CI can miss a regression in this changed adapter. Please add a held-lock case that becomes available before the negative-timeout acquire returns.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/lock/src/Distributed.php
Line: 67
Comment:
**Add negative-timeout coverage for Distributed**
The new regression test covers only `File`; the Redis E2E suite already tests contention and finite timeouts but never exercises `acquire(-1.0)`, so CI can miss a regression in this changed adapter. Please add a held-lock case that becomes available before the negative-timeout acquire returns.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Lock::acquire()documents a negative timeout as wait forever, butFileandDistributedtreated it as one non-blocking try, sowithLock(-1)could throwContention.FileandDistributedshort-circuit only on0.0and retry against anINFdeadline when the timeout is negative; zero and positive timeouts are unchanged. The coroutineMutex/Semaphorepaths already wait forever throughChannel::push().Mutex/Semaphorekeep returning false at once when held: nothing else runs there to release them, so waiting could only hang. TheLock::acquire()docblock now states this exception.FileTest::testNegativeTimeoutWaitsUntilReleaseforks a holder and assertsacquire(-1.0)blocks until it releases.Verified:
bin/monorepo check lock(pint, phpstan level 9) passes;phpunit tests/FileTest.phpon the host passes, and the new test fails against main'sFile.php; the package unit suite inappwrite-devpasses (fork tests skipped there, no pcntl). The RedisDistributedpath was not run locally.Closes #13719
Related: #13756 (merged into this branch), #13787 (same fix for
FileandDistributed)