Skip to content

Commit

Permalink
Ensure lock is released if crawl() throws an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
pennedav authored and brendanheywood committed May 29, 2020
1 parent 701a64c commit 33711f0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions classes/robot/crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 33711f0

Please sign in to comment.