wp-media / imagify-plugin

Speed up your website with lighter images without losing quality.
https://imagify.io
71 stars 25 forks source link

PHP Fatal error: Uncaught RuntimeException: Unable to claim actions. Database error #720

Open vmanthos opened 1 year ago

vmanthos commented 1 year ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug

The following PHP fatal errors popped up while testing WP Rocket - TestRail Case <- Internal Link:

[11-Apr-2023 10:24:39 UTC] PHP Fatal error:  Uncaught RuntimeException: Unable to claim actions. Database error. in /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php:864
Stack trace:
#0 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php(778): ActionScheduler_DBStore->claim_actions()
#1 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_HybridStore.php(221): ActionScheduler_DBStore->stake_claim()
#2 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/ActionScheduler_QueueRunner.php(157): ActionScheduler_HybridStore->stake_claim()
#3 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/ActionScheduler_QueueRunner.php(136): ActionScheduler_QueueRunner->do_batch()
#4 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(308): ActionScheduler_QueueRunner->run()
#5 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#6 /var/www/example.com/htdocs/wp-includes/plugin.php(517): WP_Hook->do_action()
#7 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php(52): do_action()
#8 /var/www/example.com/htdocs/wp-content/plugins/ninja-forms/includes/Libraries/BackgroundProcessing/classes/wp-async-request.php(153): ActionScheduler_AsyncRequest_QueueRunner->handle()
#9 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(308): WP_Async_Request->maybe_handle()
#10 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#11 /var/www/example.com/htdocs/wp-includes/plugin.php(517): WP_Hook->do_action()
#12 /var/www/example.com/htdocs/wp-admin/admin-ajax.php(188): do_action()
#13 {main}
  thrown in /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php on line 864
[11-Apr-2023 10:24:42 UTC] WordPress database error Table 'example_db.wp_actionscheduler_actions' doesn't exist for query SELECT COUNT(DISTINCT claim_id) FROM wp_actionscheduler_actions WHERE claim_id != 0 AND status IN ( 'pending', 'in-progress') made by do_action('wp_ajax_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, ActionScheduler_AsyncRequest_QueueRunner->maybe_dispatch, ActionScheduler_AsyncRequest_QueueRunner->allow, ActionScheduler_Abstract_QueueRunner->has_maximum_concurrent_batches, ActionScheduler_HybridStore->get_claim_count, ActionScheduler_DBStore->get_claim_count
[11-Apr-2023 10:24:42 UTC] WordPress database error Table 'example_db.wp_actionscheduler_actions' doesn't exist for query SELECT a.action_id FROM wp_actionscheduler_actions a WHERE 1=1 AND a.status IN ('pending') AND a.scheduled_date_gmt <= '2023-04-11 10:24:42' LIMIT 0, 5 made by do_action('wp_ajax_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, ActionScheduler_AsyncRequest_QueueRunner->maybe_dispatch, ActionScheduler_AsyncRequest_QueueRunner->allow, ActionScheduler_Store->has_pending_actions_due, ActionScheduler_HybridStore->query_actions, ActionScheduler_DBStore->query_actions
[11-Apr-2023 10:24:47 UTC] WordPress database error Table 'example_db.wp_actionscheduler_actions' doesn't exist for query SELECT a.action_id FROM wp_actionscheduler_actions a WHERE 1=1 AND a.hook='action_scheduler/migration_hook' AND a.status IN ('in-progress') ORDER BY a.scheduled_date_gmt ASC LIMIT 0, 1 made by require_once('wp-admin/admin.php'), require_once('wp-load.php'), require_once('/var/www/example.com/wp-config.php'), require_once('wp-settings.php'), do_action('wp_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\Migration\Controller->schedule_migration, Action_Scheduler\Migration\Scheduler->is_migration_scheduled, as_next_scheduled_action, ActionScheduler_Store->query_action, ActionScheduler_HybridStore->query_actions, ActionScheduler_DBStore->query_actions
[11-Apr-2023 10:24:47 UTC] WordPress database error Table 'example_db.wp_actionscheduler_actions' doesn't exist for query SELECT a.action_id FROM wp_actionscheduler_actions a WHERE 1=1 AND a.hook='action_scheduler/migration_hook' AND a.status IN ('pending') ORDER BY a.scheduled_date_gmt ASC LIMIT 0, 1 made by require_once('wp-admin/admin.php'), require_once('wp-load.php'), require_once('/var/www/example.com/wp-config.php'), require_once('wp-settings.php'), do_action('wp_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\Migration\Controller->schedule_migration, Action_Scheduler\Migration\Scheduler->is_migration_scheduled, as_next_scheduled_action, ActionScheduler_Store->query_action, ActionScheduler_HybridStore->query_actions, ActionScheduler_DBStore->query_actions
[11-Apr-2023 10:27:17 UTC] Cron unschedule event error for hook: rocket_critical_css_generation_cron, Error code: could_not_set, Error message: The cron event list could not be saved., Data: {"schedule":"rocket_critical_css_generation_cron_interval","args":[],"interval":300}

which is similar to this: https://github.com/wp-media/wp-rocket/issues/5435,

and:

PHP Fatal error:  Uncaught InvalidArgumentException: Unidentified action 47 in /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php:1001
Stack trace:
#0 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php(70): ActionScheduler_DBStore->mark_failure()
#1 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/ActionScheduler_QueueRunner.php(166): ActionScheduler_Abstract_QueueRunner->process_action()
#2 /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/ActionScheduler_QueueRunner.php(136): ActionScheduler_QueueRunner->do_batch()
#3 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(308): ActionScheduler_QueueRunner->run()
#4 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#5 /var/www/example.com/htdocs/wp-includes/plugin.php(565): WP_Hook->do_action()
#6 /var/www/example.com/htdocs/wp-cron.php(188): do_action_ref_array()
#7 {main}
  thrown in /var/www/example.com/htdocs/wp-content/plugins/imagify/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php on line 1001
[11-Apr-2023 11:13:28 UTC] WordPress database error Table 'example_db.wp_actionscheduler_actions' doesn't exist for query SELECT action_id FROM wp_actionscheduler_actions WHERE claim_id = 4 made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_FatalErrorMonitor->handle_unexpected_shutdown, ActionScheduler_DBStore->release_claim
[11-Apr-2023 11:13:28 UTC] WordPress database error Table 'example_db.wp_actionscheduler_claims' doesn't exist for query DELETE FROM `wp_actionscheduler_claims` WHERE `claim_id` = 4 made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_FatalErrorMonitor->handle_unexpected_shutdown, ActionScheduler_DBStore->release_claim

To Reproduce

Although not 100% reproducible the following should do the trick.

Steps to reproduce the behavior:

  1. Imagify is optimizing images.
  2. Delete the Action Scheduler tables in the database.
  3. Check the debug.log.

Expected behavior

No PHP errors should occur.

Backlog Grooming (for WP Media dev team use only)

CrochetFeve0251 commented 1 year ago

Identify the root cause

The root cause is the same as https://github.com/wp-media/wp-rocket/issues/5435, AS is creating an error when it can't fetch actions when the table doesn't exists.

Scope a solution

We could apply the same solution by logging instead of failing when AS raise an error.

Estimate the effort

Effort S

Mai-Saad commented 1 year ago

Happening in this scenario: Scenario: 1- delete AS actions table 2- fresh install and activate of the PR