1

I keep getting errors like the following:

[29-Dec-2015 03:06:14 UTC] WordPress database error Deadlock found when trying to get lock; try restarting transaction for query DELETE FROM wp_options WHERE option_name LIKE '\\_transient\\_%1451358373' ORDER BY option_id LIMIT 1000; made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), call_user_func_array, wc_custom_redirect_after_purchase, WC_Abstract_Order->update_status, wc_delete_shop_order_transients, WC_Cache_Helper::get_transient_version, WC_Cache_Helper::delete_version_transients
[29-Dec-2015 03:07:07 UTC] WordPress database error Deadlock found when trying to get lock; try restarting transaction for query DELETE FROM wp_options WHERE option_name LIKE '_transient_wpseo_sitemap_cache_shop_order_%' OR option_name LIKE '_transient_timeout_wpseo_sitemap_cache_shop_order_%' made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Abstract_Order->payment_complete, WC_Abstract_Order->update_status, WC_Abstract_Order->add_order_note, wp_insert_comment, wp_update_comment_count, wp_update_comment_count_now, clean_post_cache, clean_object_term_cache, do_action('clean_object_term_cache'), call_user_func_array, wpseo_invalidate_sitemap_cache_terms, wpseo_invalidate_sitemap_cache, WPSEO_Utils::clear_sitemap_cache
[29-Dec-2015 03:07:07 UTC] WordPress database error Deadlock found when trying to get lock; try restarting transaction for query DELETE FROM wp_options WHERE option_name LIKE '\\_transient\\_%1451358425' ORDER BY option_id LIMIT 1000; made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Abstract_Order->payment_complete, WC_Abstract_Order->update_status, wc_delete_shop_order_transients, WC_Cache_Helper::get_transient_version, WC_Cache_Helper::delete_version_transients

I think it is because of the following function I have in functions.php:

add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' ); 
function wc_custom_redirect_after_purchase() {
    global $wp;

    if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
        global $wpdb;
        $email = $_COOKIE['xxx_email'] ? $_COOKIE['xxx_email'] : $_SESSION['xxx_email'];
        $mylink = $wpdb->get_row("SELECT email FROM xxx WHERE email = '$email'");
        if (!$mylink->email) {
            wp_redirect( 'http://xxx/abc/' );
            exit;
        }
        $order_id = absint( $wp->query_vars['order-received'] );
        $order = new WC_Order($order_id);
        if (!empty($order)) {
            $order->update_status( 'completed' );
        } else {
            wp_redirect( 'http://xxx/xyz/' );
            exit;
        }
}
}

Basically, what the function does is it looks to see if the email address used to place an order is already in our database. If it ISNT in our data, then the user is redirected to a generic page telling them to confirm their email. If it IS in our database, the order status is updated to completed and the user is sent to the regular WooCommerce thank you page.

Any idea why this is throwing errors and how to fix it? It is important to note, the function usually works; it is on a live website and is working as should be. However, I'm often seeing the above-mentioned error in my error_log. So something seems to be intermittently going wrong. Any idea what?

Thanks!

2

Deadlocks happen mostly when you try to perform writes to the DB (trying to write more then one value at the same time to the same part of the DB). You specific code do not include any obvious writes so the problem comes from somewhere else.

From the statements that cause the errors it is possible to assume that you need to hunt for some code that deletes transients automatically.

  • Is there any way for me to figure out what is causing this? Some SSH command I could run to find the file that is running those specific MYSQL requests? – user3210369 Dec 29 '15 at 5:51
  • 1
    if this is consistent than start by turning off plugins – Mark Kaplun Dec 29 '15 at 6:17
  • Unfortunately, it is a live website and I cannot do that without killing it. Is there any command that I can search PHP files vis terminal? I can look for that specific query to identify what function it is, then potentially identify what is the issue. – user3210369 Dec 29 '15 at 6:59
  • 1
    Can't you simply make a backup and restore it on local server to test it there? – denis.stoyanov Dec 29 '15 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.