Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Deadlocks when processing and claiming actions #20

Open
thenbrent opened this issue May 10, 2018 · 3 comments
Open

Deadlocks when processing and claiming actions #20

thenbrent opened this issue May 10, 2018 · 3 comments

Comments

@thenbrent
Copy link
Contributor

thenbrent commented May 10, 2018

While running 3 queues of scheduled actions (with a small batch size of 5 actions) via WP CLI, I enountered the following deadlock:

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 = '2018-05-10 10:31:56', last_attempt_local = '2018-05-10 06:31:56' WHERE action_id = 803045 made by
include('phar:///usr/local/bin/wp/php/boot-phar.php'),
include('phar:///usr/local/bin/wp/php/wp-cli.php'),
WP_CLI\bootstrap,
WP_CLI\Bootstrap\LaunchRunner->process,
WP_CLI\Runner->start,
WP_CLI\Runner->_run_command_and_exit,
WP_CLI\Runner->run_command,
WP_CLI\Dispatcher\Subcommand->invoke,
call_user_func,
WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure},
call_user_func,
ActionScheduler_WPCLI_Scheduler_command->run,
ActionScheduler_WPCLI_QueueRunner->run,
ActionScheduler_Abstract_QueueRunner->process_action,
Action_Scheduler\Custom_Tables\DB_Store->log_execution

Screenshot: https://cl.ly/262n1x3m1E3Z

@thenbrent thenbrent changed the title Deadlock when processing action Deadlocks when processing and claiming actions Aug 1, 2018
@thenbrent
Copy link
Contributor Author

I'm also seeing a few of the following deadlocks when claiming actions (on a site with 8 concurrent queues processing):

WordPress database error Deadlock found when trying to get lock; try restarting transaction for query
UPDATE `wp_qftw_actionscheduler_actions` SET `claim_id` = 0 WHERE `claim_id` = 29497
made by
	include('phar:///usr/local/bin/wp/php/boot-phar.php'),
	include('phar:///usr/local/bin/wp/php/wp-cli.php'),
WP_CLI\bootstrap,
WP_CLI\Bootstrap\LaunchRunner->process,
WP_CLI\Runner->start,
WP_CLI\Runner->_run_command_and_exit,
WP_CLI\Runner->run_command,
WP_CLI\Dispatcher\Subcommand->invoke,
call_user_func,
WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure},
call_user_func,
ActionScheduler_WPCLI_Scheduler_command->run,
ActionScheduler_WPCLI_QueueRunner->run,
Action_Scheduler\Custom_Tables\DB_Store->release_claim

@rrennick
Copy link
Contributor

rrennick commented Mar 1, 2019

@thenbrent Do you think a try/catch, usleep & retry would be a good way to mitigate this?

@thenbrent
Copy link
Contributor Author

@rrennick I think that's probably the best we can do. Sleep + retry won't reduce the likelihood of it happening much, because it's equally likely there will be multiple queues happening later, so the deadlock may occur again on a 2nd attempt. We could mitigate that by retrying a number of times, like up to 10, but that all starts to feel very hacky...

I'm not sure how (if) we can optimize the query or schema to prevent it completely though either, so try/catch, usleep & retry might be the best we can do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants