action-scheduler icon indicating copy to clipboard operation
action-scheduler copied to clipboard

PHP Fatal error: Uncaught Error: Class "ActionScheduler_Lock" on plugin uninstall

Open boonedev opened this issue 1 year ago • 3 comments

Our plugin is using ActionScheduler 3.7.1. We are seeing a PHP Fatal error: Uncaught Error: Class "ActionScheduler_Lock" on plugin uninstall.

Steps to reproduce:

  1. Install version 3.7.1 and setup a basic plugin using this code
<?php
/**
 * Action Scheduler Test
 *
 * @wordpress-plugin
 * Plugin Name:       Action Scheduler Test
 * Version:           1.0
 */

// If this file is called directly, abort.
if (! defined('WPINC') ) {
    die;
}

error_log(time() . ' Loading Action Scheduler Test Plugin File');

register_activation_hook(__FILE__, 'ast_activation');
register_deactivation_hook(__FILE__, 'ast_deactivation');
register_uninstall_hook(__FILE__, 'ast_uninstall');

function ast_activation()
{
    error_log(time() . ' Activating Action Scheduler Test');   
}

function ast_deactivation()
{
    error_log(time() . ' Deactivating Action Scheduler Test');   
}

function ast_uninstall()
{
    error_log(time() . ' Uninstalling Action Scheduler Test');   
}

require_once plugin_dir_path(__FILE__) . '/vendor/woocommerce/action-scheduler/action-scheduler.php';

  1. Install, activate, deactivate, uninstall

Here is the error log we're seeing after uninstall:

PHP Fatal error:  Uncaught Error: Class "ActionScheduler_Lock" not found in /Users/matt/Local Sites/test/app/public/wp-content/plugins/action-scheduler-test/vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler.php:29
Stack trace:
#0 /Users/matt/Local Sites/test/app/public/wp-content/plugins/action-scheduler-test/vendor/woocommerce/action-scheduler/classes/ActionScheduler_QueueRunner.php(109): ActionScheduler::lock()
#1 /Users/matt/Local Sites/test/app/public/wp-includes/class-wp-hook.php(324): ActionScheduler_QueueRunner->maybe_dispatch_async_request('')
#2 /Users/matt/Local Sites/test/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#3 /Users/matt/Local Sites/test/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /Users/matt/Local Sites/test/app/public/wp-includes/load.php(1260): do_action('shutdown')
#5 [internal function]: shutdown_action_hook()
#6 {main}
  thrown in /Users/matt/Local Sites/test/app/public/wp-content/plugins/action-scheduler-test/vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler.php on line 29

boonedev avatar Jan 23 '24 16:01 boonedev

@boonedev I suspect this is happening because the full Action Scheduler package is still getting loaded during the request that deletes it, so it still has a callback hooked to shutdown even though the code has been removed. You might be able to avoid this if you ensure the current request is not uninstalling something before loading the library. https://developer.wordpress.org/reference/functions/register_uninstall_hook/

coreymckrill avatar Jan 25 '24 17:01 coreymckrill

Marking this as "enhancement" in case we want to investigate whether there's anything protections against this that we could add within Action Scheduler itself...

coreymckrill avatar Jan 25 '24 18:01 coreymckrill