Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
boonedev opened this issue Jan 23, 2024 · 2 comments
Labels
priority: normal The issue/PR is normal priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement.

Comments

@boonedev
Copy link

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

@coreymckrill
Copy link
Contributor

@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 coreymckrill added type: enhancement The issue is a request for an enhancement. priority: normal The issue/PR is normal priority—not many people are affected or there’s a workaround, etc. labels Jan 25, 2024
@coreymckrill
Copy link
Contributor

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: normal The issue/PR is normal priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants