Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure lock is released if crawl() throws an exception #128

Merged
merged 5 commits into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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