From eb8abbae23b4d2483e677479ea87c4bb437aa6fb Mon Sep 17 00:00:00 2001 From: Sevtlin Kalendzhiev Date: Mon, 13 Aug 2018 18:57:19 +0200 Subject: [PATCH] [fix] remove destructor in mutex Mutex destructor is used to as a fail safe to release locks in case process is terminated unexpectedly, this is not really needed and could lead to errors * The actual lock provider responsible for releasing the lock could be destructed before the mutex, during shutdown there is no guarantee in order of which objects are destructed * All lock providers extend the LockAbstaract class which already has a destructor responsible for freeing locks in case of failure * Throwig exception in the destructor is not a good idea, doing so triggers a fatal error --- src/Mutex.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/Mutex.php b/src/Mutex.php index 93cf4eb..08df685 100644 --- a/src/Mutex.php +++ b/src/Mutex.php @@ -82,29 +82,6 @@ public function releaseLock() return false; } - /** - * Try to release any obtained locks when object is destroyed - * - * This is a safe guard for cases when your php script dies unexpectedly. - * It's not guaranteed it will work either. - * - * You should not depend on __destruct() to release your locks, - * instead release them with `$released = $this->releaseLock()`A - * and check `$released` if lock was properly released - */ - public function __destruct() - { - while ($this->isAcquired()) { - $released = $this->releaseLock(); - if (!$released) { - throw new UnrecoverableMutexException(sprintf( - 'Cannot release lock in Mutex __destruct(): %s', - $this->name - )); - } - } - } - /** * Check if Mutex is acquired *