woocommerce / action-scheduler

A scalable, traceable job queue for background processing large queues of tasks in WordPress. Specifically designed for distribution in WordPress plugins (and themes) - no server access required.
https://actionscheduler.org
GNU General Public License v3.0
629 stars 114 forks source link

Incorrect table name '' in ActionScheduler_DBStoreMigrator #436

Closed pokhiii closed 4 years ago

pokhiii commented 4 years ago
PHP Fatal error:  Uncaught RuntimeException: Error saving action:
Error saving action: Incorrect table name '' in /wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php:44\nStack trace:\n
#0 /wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php(225): ActionScheduler_DBStoreMigrator->save_action(Object(ActionScheduler_Action), NULL)\n
#1 /wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php(177): ActionScheduler_HybridStore->save_action(Object(ActionScheduler_Action))\n
#2 /wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php(84): ActionScheduler_ActionFactory->store(Object(ActionScheduler_Action))\n
#3 /wp-content/plu in /wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php on line 44
pokhiii commented 4 years ago

Okay, those subscriptions which missed renewals due to WCS2.5.7 will automatically be renewed when I upgrade to WCS3.0.1?

pokhiii commented 4 years ago

Or I need to manually renew them?

rrennick commented 4 years ago

I would expect that the renewal actions are in the actionscheduler tables but you'll need to assess for manual renewals once you have everything back up and running.

pokhiii commented 4 years ago

Sorry I didn't get you what are you suggesting. Are you saying there is a 50-50 chance for automatically renewing? If that is the case, how long should I wait for it before manually triggering them?

rrennick commented 4 years ago

After you have cleared the duplicate pending actions you'll have a list of remaining pending actions. Those ones will renew automatically. WCS may create some more via retries, etc. I'm not familiar enough with that part of WCS to say for certain where things will be with other subs that need renewal.

pokhiii commented 4 years ago

@rrennick Thank you sir for the responses you've provided today. I really can't figure out your reasoning behind the duplicate actions from the actionscheduler_actions table. I do not understand what the result of that query is signifying. So, I think we'll be moving forward with just upgrading WCS to 3.0.1 and see what happens. Do you think it can be a problem? We should hold?

pokhiii commented 4 years ago

Hi @rrennick, just wanted to update you that we upgrade WCS to 3.0.1 and all the renewals started happening as soon as it was upgraded. We ran the update with the FUE being disabled. However, checking the error log we noticed 11 occurrences of

WordPress database error Deadlock found when trying to get lock; try restarting transaction for query UPDATE wp_actionscheduler_actions SET attempts = attempts+1, status='in-progress', last_attempt_gmt = '2020-01-27 21:33:01', last_attempt_local = '2020-01-27 15:33:01' WHERE action_id = 1396584 /* From [my-domain.com/wp-admin/admin-ajax.php?action=as_async_request_queue_runner&nonce=20b5ba58c7] in [/path/to/install/wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php:752] */ 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, do_action('action_scheduler_run_queue'), WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_QueueRunner->run, ActionScheduler_QueueRunner->do_batch, ActionScheduler_Abstract_QueueRunner->process_action, ActionScheduler_DBStore->log_execution, referer: https://my-domain.com/wp-admin/admin-ajax.php?action=as_async_request_queue_runner&nonce=20b5ba58c7

Also, our hosting reported seeing 499s response. The add_filter code you provided was present in our functions.php file.

rrennick commented 4 years ago

I really can't figure out your reasoning behind the duplicate actions from the actionscheduler_actions table.

Each of the duplicates was going to re-charge a renewal fee.

WHERE action_id = 1396584

Can you see which action that is?

rrennick commented 4 years ago

If you continue to see the deadlock errors in your error log, temporarily add

add_filter( 'action_scheduler_allow_async_request_runner', '__return_false' );

for a day or so to see whether that eliminates the deadlock issue.

pokhiii commented 4 years ago

Can you see which action that is?

{
    "action_id": 1396584,
    "hook": "woocommerce_deliver_webhook_async",
    "status": "complete",
    "scheduled_date_gmt": "2020-01-27 21:29:17",
    "scheduled_date_local": "2020-01-27 15:29:17",
    "args": "{\"webhook_id\":1,\"arg\":922689}",
    "schedule": "O:30:\"ActionScheduler_SimpleSchedule\":2:{s:22:\"\0*\0scheduled_timestamp\";i:1580160557;s:41:\"\0ActionScheduler_SimpleSchedule\0timestamp\";i:1580160557;}",
    "group_id": 6,
    "attempts": 0,
    "last_attempt_gmt": "2020-01-27 21:33:02",
    "last_attempt_local": "2020-01-27 15:33:02",
    "claim_id": 0
}

I'll add that filter and let you know whether we are still seeing the deadlock issue.

glagonikas commented 4 years ago

Without any intention to hijack the thread, we too experienced the "Incorrect table name" issue during migration, but hasn't come up since.

We don't use Follow-up emails, but have some custom code that works quite similar to them.

@rrennick any chance you can advise what caused this issue and how Follow-up fixed the bug on their latest version? We can then see if the fix is applicable to our code too.

p.s. We've not identified any issues with the migration so far and haven't seen any duplicate renewals.

rrennick commented 4 years ago

I'll add that filter and let you know whether we are still seeing the deadlock issue.

@abhishek-pokhriyal Thanks for the follow up. Can you post your results on #441?

we too experienced the "Incorrect table name" issue during migration, but hasn't come up since.

@glagonikas That's good to know. Older versions of FUE were partially loading its copy of Action Scheduler before AS was properly initialized. That resulted in some classes from 2.2.X being used instead of the version of the class from 3.0.X.

pokhiii commented 4 years ago

@rrennick I've created a copy of the live site to test this out first. However, I'm not able to replicate the deadlock error. Do you think it's probably because the renewal orders are not going to Payment gateway (due to automatic payment being disabled on the environment) and gets stuck on "Pending payment"?

rrennick commented 4 years ago

Do you think it's probably because the renewal orders are not going to Payment gateway

That's the most likely cause. Without the renewals being processed you don't have enough AS activity to trigger a deadlock.

pokhiii commented 4 years ago

Thanks, @rrennick. I'm going to use this plugin to enable auto payments for some subscriptions and then going to renew them. One major concern, I'm using Stripe in test mode, but since this is real data I fear auto payment may charge them. If you've have any idea about this, please let me.

rrennick commented 4 years ago

If you've have any idea about this, please let me.

I think the general idea for testing in staging with that plugin is to create test subscriptions that you use. As far as I know, the Stripe test gateway will not accept real credit cards. The list of card numbers to use when testing Stripe are listed at https://stripe.com/docs/testing.

glagonikas commented 4 years ago

@abhishek-pokhriyal I would recommend that you simply switch Stripe to test mode on your staging, at /wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe, enable automatic payments, then create the subscriptions manually via admin or the front-end and set them to renew at around the same time (or even better, exactly the same time).

As far as i can tell, the plugin you linked will allow you to process renewal payments using your live credentials on a staging environment, which should probably be avoided.

pokhiii commented 4 years ago

Thanks for your input @rrennick and @glagonikas. I was able to run the subscription renewals to payment processing. I scheduled 4 subscriptions at the same time and carefully watch error logs but there was nothing! I'm going to go ahead use the code here on my live site. I'm posting the current stats on #441.

pokhiii commented 4 years ago

Hi @rrennick,

It's been a couple of days now and the renewals are coming up fine, we have not noticed any case of multiple payments. However, till now we have not activated Follow-Up Emails back again (I'm extremely scared to click on that Activate button). We v4.8.22 (the latest version) of FUE currently deactivated on the live site. We need to get that up and running again but I'm afraid it can mess up the renewals and payments again.

Could you suggest me some steps/precautions that I can take to make sure those multiple payment issue with renewals does not happen? Do you even recommend to activate it back again yet?

rrennick commented 4 years ago

Do you even recommend to activate it back again yet?

The old version of FUE loaded AS incorrectly resulting in fatal errors. We have had lots of customers update FUE and not have issues with the latest version. It should be fine to activate.

rrennick commented 4 years ago

I'm going to close this as the two issues discussed are addressed by #450 and #452.

kevinbrown041 commented 4 years ago

I am also getting this issue. My logs are showing a missing table. Looks like it's trying to find the wrong DB and table. It's look for DB "gigrt_wp4.a" but the DB is at "gigrt_wp4". The tables are also called "a". Very strange. WHere did it get this from?

Here's a sample of my error logs. I'm getting this all day long.

[Sun Feb 16 19:21:07.897807 2020] [proxy_fcgi:error] [pid 24100:tid 140505484551936] [client 107.77.195.152:35496] AH01071: Got error 'PHP message: WordPress database error Table 'gigrt_wp4.a' doesn't exist for query SELECT a.action_id FROM a WHERE a.hook='action_scheduler/migration_hook' AND a.status='in-progress' ORDER BY scheduled_date_gmt DESC LIMIT 1 made by shutdown_action_hook, do_action('shutdown'), 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_HybridStore->find_action, ActionScheduler_DBStore->find_actionPHP message: WordPress database error Table 'gigrt_wp4.a' doesn't exist for query SELECT a.action_id FROM a WHERE a.hook='action_scheduler/migration_hook' AND a.status='pending' ORDER BY scheduled_date_gmt ASC LIMIT 1 made by shutdown_action_hook, do_action('shutdown'), 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_HybridStore->find_action, ActionScheduler_DBStore->find_actionPHP message: WordPress database error Table 'gigrt_wp4.a' doesn't exist for query SELECT a.action_id FROM a WHERE a.hook='action_scheduler/migration_hook' AND a.status='in-progress' ORDER BY scheduled_date_gmt DESC LIMIT 1 made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\\Migration\\Controller->schedule_migration, Action_Scheduler\\Migration\\Scheduler->schedule_migration, as_next_scheduled_action, ActionScheduler_HybridStore->find_action, ActionScheduler_DBStore->find_actionPHP message: WordPress database error Table 'gigrt_wp4.a' doesn't exist for query SELECT a.action_id FROM a WHERE a.hook='action_scheduler/migration_hook' AND a.status='pending' ORDER BY scheduled_date_gmt ASC LIMIT 1 made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\\Migration\\Controller->schedule_migration, Action_Scheduler\\Migration\\Scheduler->schedule_migration, as_next_scheduled_action, ActionScheduler_HybridStore->find_action, ActionScheduler_DBStore->find_actionPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE slug='action-scheduler-migration'' at line 1 for query SELECT group_id FROM WHERE slug='action-scheduler-migration' made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\\Migration\\Controller->schedule_migration, Action_Scheduler\\Migration\\Scheduler->schedule_migration, as_schedule_single_action, ActionScheduler_ActionFactory->single, ActionScheduler_ActionFactory->store, ActionScheduler_HybridStore->save_action, ActionScheduler_DBStoreMigrator->save_action, ActionScheduler_DBStore->save_action, ActionScheduler_DBStore->get_group_idPHP message: WordPress database error Incorrect table name '' for query SHOW FULL COLUMNS FROM `` made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\\Migration\\Controller->schedule_migration, Action_Scheduler\\Migration\\Scheduler->schedule_migration, as_schedule_single_action, ActionScheduler_ActionFactory->single, ActionScheduler_ActionFactory->store, ActionScheduler_HybridStore->save_action, ActionScheduler_DBStoreMigrator->save_action, ActionScheduler_DBStore->save_action, ActionScheduler_DBStore->get_group_id, ActionScheduler_DBStore->create_groupPHP message: WordPress database error Incorrect table name '' for query SHOW FULL COLUMNS FROM `` made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, Action_Scheduler\\Migration\\Controller->schedule_migration, Action_Scheduler\\Migration\\Scheduler->schedule_migration, as_schedule_single_action, ActionScheduler_ActionFactory->single, ActionScheduler_ActionFactory->store, ActionScheduler_HybridStore->save_action, ActionScheduler_DBStoreMigrator->save_action, ActionScheduler_DBStore->save_actionPHP message: PHP Fatal error: Uncaught RuntimeException: Error saving action: Error saving action: Incorrect table name '' in /var/www/vhosts/gigrev.com/shop.gigrev.com/wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php:44\nStack trace:\n#0 /var/www/vhosts/gigrev.com/shop.gigrev.com/wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php(225): ActionScheduler_DBStoreMigrator->save_action(Object(ActionScheduler_Action), NULL)\n#1 /var/www/vhosts/gigrev.com/shop.gigrev.com/wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php(177): ActionScheduler_HybridStore->save_action(Object(ActionScheduler_Action))\n#2 /var/www/vhosts/gigrev.com/shop.gigrev.com/wp-content/plugins/woocommerce-subscriptions/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php(84): A...', referer: https://shop.gigrev.com/thanks.......

This is on a live site. I tried to run the migrator from command line but it also just shows an error; Warning: Failed migrating action with ID 408025 Warning: Failed migrating action with ID 408033 Warning: Attempting to reduce used memory... Migrating 100 actions 100% [======================================] 0:01 / 1:54 Completed migration of 100 actions Warning: Failed migrating action with ID 406870 Migrating 100 actions 1 % [> ] 0:00 / 0:00Warning: Failed migrating action with ID 406876 Warning: Failed migrating action with ID 406884 Warning: Failed migrating action with ID 406898 Warning: Failed migrating action with ID 406926 Warning: Failed migrating action with ID 406937

As far as the site is concerned, I don't get duplicate actions and card processing looks fine.

Can anyone shed any light on this?

rrennick commented 4 years ago

Can anyone shed any light on this?

If you have AS installed as a plugin update it to version 3.1.0. If it's a library in another plugin you have installed then you need to install version 3.1.0.

kevinbrown041 commented 4 years ago

3.1.0 is inc with WooSubscriptions right? Also, I figured out the issue. The migrator was trying to migrate actions for the official MailChimp plugin but it failed. Either because the plugin was no longer installed or the length of the content was more than 192 char. I'm unsure which caused the issue but my queue is running now.

rrennick commented 4 years ago

@kevinbrown041 No, 3.0.1 is in WC Subs.

Either because the plugin was no longer installed or the length of the content was more than 192 char.

The length would be the reason. AS isn't aware of what plugins create actions. 3.1.0 addresses the length issue.

kevinbrown041 commented 4 years ago

Great to know that. Thanks @rrennick Can I ask a dumb question. I got AS with Subscriptions. Do I just replace AS 3.0.1 in that dir with the new version 3.1.0 ?

rrennick commented 4 years ago

Do I just replace AS 3.0.1 in that dir with the new version 3.1.0 ?

Download the zip and upload it as a standalone plugin through the plugin installer.