From e6f4190203cc2307b152a553fe02ca2997889655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Mon, 30 Nov 2020 17:20:10 +0100 Subject: [PATCH] MDL-70357 cron: Catch Throwables not just Exceptions when running tasks Starting from PHP 7, most language errors throw Error exceptions. We want to deal with those equally as with any other exception so we need to catch all Throwables here. --- lib/cronlib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cronlib.php b/lib/cronlib.php index 4190bf2892d..0cf405b210f 100644 --- a/lib/cronlib.php +++ b/lib/cronlib.php @@ -182,7 +182,7 @@ function cron_run_adhoc_tasks(int $timenow, $keepalive = 0, $checklimits = true) try { $task = \core\task\manager::get_next_adhoc_task(time(), $checklimits); - } catch (Exception $e) { + } catch (\Throwable $e) { if ($adhoclock) { // Release the adhoc task runner lock. $adhoclock->release(); @@ -260,7 +260,7 @@ function cron_run_inner_scheduled_task(\core\task\task_base $task) { } mtrace('Scheduled task complete: ' . $fullname); \core\task\manager::scheduled_task_complete($task); - } catch (Exception $e) { + } catch (\Throwable $e) { if ($DB && $DB->is_transaction_started()) { error_log('Database transaction aborted automatically in ' . get_class($task)); $DB->force_transaction_rollback(); @@ -348,7 +348,7 @@ function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) { } mtrace("Adhoc task complete: " . get_class($task)); \core\task\manager::adhoc_task_complete($task); - } catch (Exception $e) { + } catch (\Throwable $e) { if ($DB && $DB->is_transaction_started()) { error_log('Database transaction aborted automatically in ' . get_class($task)); $DB->force_transaction_rollback();