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
2525{
2626 /**
2727 * Acquire a transaction-level advisory lock with configurable wait and access modes.
28- *
29- * TODO: Cover with tests
3028 */
3129 public function acquireTransactionLevelLock (
3230 PDO $ dbConnection ,
@@ -48,8 +46,24 @@ public function acquireTransactionLevelLock(
4846 /**
4947 * Acquire a session-level advisory lock with configurable wait and access modes.
5048 *
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.
5367 */
5468 public function acquireSessionLevelLock (
5569 PDO $ dbConnection ,
You can’t perform that action at this time.
0 commit comments