From 44cedf2225885dd363a46636956faf7bd02e2648 Mon Sep 17 00:00:00 2001 From: Matt Ford Date: Wed, 6 Mar 2024 16:58:00 +0000 Subject: [PATCH] Only acquire the lock in `Lock::get` if a callback was not passed, otherwise only check if it is available --- src/Illuminate/Cache/Lock.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Cache/Lock.php b/src/Illuminate/Cache/Lock.php index 4868fdf82a50..f2e0dbbf4cbf 100644 --- a/src/Illuminate/Cache/Lock.php +++ b/src/Illuminate/Cache/Lock.php @@ -88,17 +88,14 @@ abstract protected function getCurrentOwner(); */ public function get($callback = null) { - $result = $this->acquire(); - - if ($result && is_callable($callback)) { - try { + // If a callable is passed, only check whether the lock is available. + if (is_callable($callback)) { + $owner = $this->getCurrentOwner(); + if (empty($owner) || $owner === $this->owner()) { return $callback(); - } finally { - $this->release(); } } - - return $result; + return $this->acquire(); } /**