From 33711f0dc6c4088f70a5b40664a5e8cb856fbb7e Mon Sep 17 00:00:00 2001 From: David M Penner Date: Wed, 18 Mar 2020 15:12:00 -0400 Subject: [PATCH] Ensure lock is released if crawl() throws an exception --- classes/robot/crawler.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/classes/robot/crawler.php b/classes/robot/crawler.php index 6fce7fa..4c5fcb4 100644 --- a/classes/robot/crawler.php +++ b/classes/robot/crawler.php @@ -569,9 +569,17 @@ public function process_queue($verbose = false) { continue; } - $this->crawl($node, $verbose); - - $lock->release(); + // Wrap crawl in a try-catch-finally to ensure lock is released. + // Without this, if crawl() throws, the underlying exception never + // gets reported because Moodle complains about the improper use of + // the lock. + try { + $this->crawl($node, $verbose); + } catch (\Throwable $e) { + throw $e; + } finally { + $lock->release(); + } $hastime = time() < $cronstop; }