From 050d05dee5aeed5f9fda8d4187ac580a04e4d655 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Thu, 27 Mar 2025 14:58:19 +0100 Subject: [PATCH 1/2] Fix custom error handler not restored if fatal Fix https://github.com/woocommerce/action-scheduler/issues/1253 --- classes/abstracts/ActionScheduler_Abstract_QueueRunner.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php b/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php index 1b51c301..6ef15e42 100644 --- a/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php +++ b/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php @@ -78,6 +78,7 @@ function ( $type, $message ) { }, E_USER_ERROR | E_RECOVERABLE_ERROR ); + add_action( 'shutdown', 'restore_error_handler', -10 ); /* * The nested try/catch structure is required because we potentially need to convert thrown errors into @@ -112,6 +113,7 @@ function ( $type, $message ) { $this->handle_action_error( $action_id, $e, $context, $valid_action ); } finally { restore_error_handler(); + remove_action( 'shutdown', 'restore_error_handler', -10 ); } if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) { From 6fd2654a686c9181b59ad6b3302b1002f190a627 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Thu, 27 Mar 2025 15:00:52 +0100 Subject: [PATCH 2/2] Update ActionScheduler_Abstract_QueueRunner.php --- classes/abstracts/ActionScheduler_Abstract_QueueRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php b/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php index 6ef15e42..64ab1eb5 100644 --- a/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php +++ b/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php @@ -78,7 +78,7 @@ function ( $type, $message ) { }, E_USER_ERROR | E_RECOVERABLE_ERROR ); - add_action( 'shutdown', 'restore_error_handler', -10 ); + add_action( 'shutdown', 'restore_error_handler', -10, 0 ); /* * The nested try/catch structure is required because we potentially need to convert thrown errors into