File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,6 @@ final class PostgresAdvisoryLocker
25
25
{
26
26
/**
27
27
* Acquire a transaction-level advisory lock with configurable wait and access modes.
28
- *
29
- * TODO: Cover with tests
30
28
*/
31
29
public function acquireTransactionLevelLock (
32
30
PDO $ dbConnection ,
@@ -48,8 +46,24 @@ public function acquireTransactionLevelLock(
48
46
/**
49
47
* Acquire a session-level advisory lock with configurable wait and access modes.
50
48
*
51
- * TODO: Write that transaction-level is recommended.
52
- * TODO: Cover with tests
49
+ * ⚠️ You MUST retain the returned handle in a variable.
50
+ * If the handle is not stored and is immediately garbage collected,
51
+ * the lock will be released in the lock handle __destruct method.
52
+ *
53
+ * @example
54
+ * $handle = $locker->acquireSessionLevelLock(...); // ✅ Lock held
55
+ *
56
+ * $locker->acquireSessionLevelLock(...); // ❌ Lock immediately released
57
+ *
58
+ * ⚠️ Transaction-level advisory locks are strongly preferred over session-level locks.
59
+ * Session-level locks persist beyond transactions and may lead to deadlocks
60
+ * or require manual cleanup (e.g. `pg_advisory_unlock_all()`).
61
+ *
62
+ * Use session-level locks only when transactional locks are not suitable
63
+ * (transactions are not possible or redundant).
64
+ *
65
+ * @see SessionLevelLockHandle::__destruct
66
+ * @see acquireTransactionLevelLock() for preferred locking strategy.
53
67
*/
54
68
public function acquireSessionLevelLock (
55
69
PDO $ dbConnection ,
You can’t perform that action at this time.
0 commit comments