From 7d2e603d0157db9968d5673109a0e5ac6f23ffc7 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Tue, 27 Feb 2024 12:40:25 +1100 Subject: [PATCH] fix: add more logging to shutdown and signal handler Resolves #869 --- classes/local/execution/engine.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classes/local/execution/engine.php b/classes/local/execution/engine.php index a89bf73d..3525d0ab 100644 --- a/classes/local/execution/engine.php +++ b/classes/local/execution/engine.php @@ -349,10 +349,22 @@ public function initialise() { } catch (\Throwable $thrown) { $this->abort($thrown); } + + // Register signal handler - if a signal caused the dataflow to stop. + \core_shutdown_manager::register_signal_handler(function ($signo){ + $error = error_get_last(); + $this->logger->log(Logger::NOTICE, 'Engine: shutdown signal ({signo}) received', ['signo' => $signo, 'lasterror' => $error]); + return \core\local\cli\shutdown::signal_handler($signo); + }); + // Register shutdown handler - if request is ended by client, abort and finalise flow. \core_shutdown_manager::register_function(function (){ + $this->logger->log(Logger::DEBUG, 'Engine: shutdown handler was called'); + // If the script has stopped and flow is not finalised then abort. if (!in_array($this->status, [self::STATUS_FINALISED, self::STATUS_ABORTED])) { + $error = error_get_last(); + $this->logger->log(Logger::ERROR, 'Engine: shutdown happened abruptly', ['lasterror' => $error]); $this->set_status(self::STATUS_ABORTED); $this->run->finalise($this->status, $this->export()); }