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 InvalidArgumentException: The group "rocket-rucss" does not exist. #6119

Closed
khalilgharbaoui opened this issue Aug 27, 2023 · 9 comments · Fixed by #6156 or #6177
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [XS] < 1 day of estimated development time module: remove unused css needs: environment priority: high Issues which should be resolved as quickly as possible severity: minor Defect that does not affect functionality type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@khalilgharbaoui
Copy link
Contributor

There is a conflict with woocommerce and wp-rocket, if you have the “remove unused CSS feature” in wp-rocket checked.
You will get the error you have noted.

Workaround:

Uncheck the “remove unused CSS” in wp-rocket and the problem goes away.

PHP Fatal error: Uncaught InvalidArgumentException: The group "rocket-rucss" does not exist. in /srv/users/stgleather/apps/stgleather/public/wp-content/plugins/woocommerce/packages/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php:907

also see: https://wordpress.org/support/topic/the-group-rocket-rucss-does-not-exist/#post-17004056

@piotrbak
Copy link
Contributor

Related issue on Action Scheduler repo:
woocommerce/action-scheduler#972

@piotrbak piotrbak added type: bug Indicates an unexpected problem or unintended behavior 3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting priority: high Issues which should be resolved as quickly as possible needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. severity: minor Defect that does not affect functionality module: remove unused css labels Aug 28, 2023
@piotrbak
Copy link
Contributor

piotrbak commented Aug 28, 2023

Thanks for creating the issue @khalilgharbaoui have you contacted our support team about this issue? It would be good to have access to the affected website in order to investigate it further.

@piotrbak
Copy link
Contributor

piotrbak commented Sep 4, 2023

@khalilgharbaoui Is this happening to you even after reactivating RUCSS? If so, could you share with us credentials to your website + SFTP, so we could investigate this? You could reach our support or send them directly to piotr[at]wp-media.me.

@CrochetFeve0251
Copy link
Contributor

CrochetFeve0251 commented Sep 5, 2023

Reproduce the issue

I succeeded to reproduce the issue after looking at the logic.
To recreate the issue we need to:

  • Make sure the group doesn't exists in the table actionscheduler_groups.
  • Prevent the RUCSS to add any element to the queue.
  • Make sure the logic from the plugin Action Scheduler is loaded.

To prevent any element to be added to the Queue can bail out at the beginning of the method [process_pending_jobs](https://github.com/wp-media/wp-rocket/blob/b520071b602528ea2af6b1fae3280f36a45d7e78/inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php#L576).

To load the Action Scheduler plugin we need to comment the line require_once WP_ROCKET_INC_PATH . 'Dependencies' . DIRECTORY_SEPARATOR . 'ActionScheduler' . DIRECTORY_SEPARATOR . 'action-scheduler.php'; in the file inc/main.php and install AS plugin.

Then activate RUCSS and you should see the exception when the Queue is running.

Identify the root cause

The root cause of this issue is that the group is created when an element is added and not when the queue is runned.

Scope a solution

A way to solve that issue is to check for the group being created before executing the queue.
The method get_group_ids could provide us an clean way to add it but it is protected.
Due to that what I propose is to create an adapter that will extend DataStore that will wrap around a DataStore and provide us the method we need thought reflection when the wrapped DataStore is an instance of ActionScheduler_DBStore.
It is a bit dirty but the only other way would be to request to AS to change the visibility of that method.

What do you think @engahmeds3ed ?

@engahmeds3ed
Copy link
Contributor

Reproduce the issue

This issue happens when:

  1. Our RUCSS queue runner is running before Action Scheduler's default queue runner
    This can happen in very rare cases but to simulate it, you need to change this line to be:
[ 'initialize_rucss_queue_runner', 0 ],

You need to do this change to the plugin while it's not active.

  1. RUCSS is enabled but no job is created yet.
    You can simulate this as @CrochetFeve0251 mentioned by adding the following return line in the start of this method:
return;

Also you need to remove the rocket-rucss group from wp_actionscheduler_groups database table.

  1. Action scheduler's standalone plugin with version >= 3.6.0 is active.
    You need to enable WPR before enabling this Action Scheduler standalone plugin.

Identify the root cause

As per our investigation on that, this is what we think:

we are not setting the store object so it's null exactly like the default queue runner here
and both (custom runner and default runner) are running every_minute.

So Based on that code, both runners will share the store instance (because it's singleton design pattern and both CRONs are on the same request)

What happens here is that the custom runner is running before the default runner passing the group to the store stake_claim method here

and based on that code that was added in this woocommerce/action-scheduler#905 you are setting the group item inside claim_filters and as we use the same object for store in both queue runners, the group will be kept the one that added in the custom queue runner.

Scope a solution

We don't need to create the group (after a discussion with AS team, they don't like creating the group till a job comes up), we just need to fix the root cause not to let out queue runner interfere with the default or any other runners.
So here and here we need to add the following line:

$this->store->set_claim_filter( 'group', '' );

I tested the fix locally with @CrochetFeve0251 help and it worked.

Estimated effort

[XS]

The hard part of this issue is to reproduce the issue in a consistent way.

khalilgharbaoui added a commit to khalilgharbaoui/wp-rocket that referenced this issue Sep 10, 2023
See:  wp-media#6119 for details

TL;DR

Fixes error:
```
PHP Fatal error: Uncaught InvalidArgumentException: The group "rocket-rucss" does not exist. in /srv/users/stgleather/apps/stgleather/public/wp-content/plugins/woocommerce/packages/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php:907
```
@khalilgharbaoui
Copy link
Contributor Author

khalilgharbaoui commented Sep 10, 2023

@khalilgharbaoui Is this happening to you even after reactivating RUCSS? If so, could you share with us credentials to your website + SFTP, so we could investigate this? You could reach our support or send them directly to piotr[at]wp-media.me.

Hi @piotrbak,

Unfortunately, I can not provide you with the credentials, the system I am working on is private.
I did however make a PR #6156 with the changes suggested by @engahmeds3ed and also applied the change and tested it on my live code, which works fine as we speak.
I no longer see the error or its related issues. Thanks, @engahmeds3ed

Hope that helps, and would be nice if that gets merged in, so I don't have to edit my files on the next update.

Salaam 👋🏽

@piotrbak piotrbak added effort: [XS] < 1 day of estimated development time and removed needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. labels Sep 12, 2023
@vmanthos vmanthos added this to the 3.15.1 milestone Sep 15, 2023
@AghaFarokh
Copy link

AghaFarokh commented Sep 16, 2023

@engahmeds3ed
Hello dear
I've added this line
$this->store->set_claim_filter( 'group', '' );
in here
and now I'm getting this error

PHP Fatal error: Uncaught Error: Call to undefined method ActionScheduler_HybridStore::set_claim_filter() in /var/www/html/wp-content/plugins/wp-rocket/inc/Engine/Common/Queue/RUCSSQueueRunner.php:220
Stack trace:
#0 /var/www/html/wp-content/plugins/wp-rocket/inc/Engine/Common/Queue/RUCSSQueueRunner.php(175): WP_Rocket\Engine\Common\Queue\RUCSSQueueRunner->do_batch()
#1 /var/www/html/wp-includes/class-wp-hook.php(310): WP_Rocket\Engine\Common\Queue\RUCSSQueueRunner->run()
#2 /var/www/html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters()
#3 /var/www/html/wp-includes/plugin.php(565): WP_Hook->do_action()
#4 /var/www/html/wp-cron.php(191): do_action_ref_array()
#5 {main}
thrown in /var/www/html/wp-content/plugins/wp-rocket/inc/Engine/Common/Queue/RUCSSQueueRunner.php on line 220

@engahmeds3ed
Copy link
Contributor

@AghaFarokh This means that you have an older version of Action scheduler, can u plz try installing action scheduler's standalone plugin (version >= 3.6.0).

We need also to guard against that in our code to have something like:

if ( method_exists( $this->store, 'set_claim_filter' ) ) {
    $this->store->set_claim_filter( 'group', '' );
}

@AghaFarokh
Copy link

Actually I didn't have a separate standalone AS plugin and my WordPress is updated to the latest version
But thank you, since I've installed the Action Scheduler standalone plugin it has been fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [XS] < 1 day of estimated development time module: remove unused css needs: environment priority: high Issues which should be resolved as quickly as possible severity: minor Defect that does not affect functionality type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
6 participants