Wordpress

My encounter with Deadlocks in WooCommerce

By May 23, 2018 July 20th, 2019 No Comments

WordPress database error Deadlock found while trying to get lock;

Ever seen something like above? Chances are you are using WooCommerce or have a lot of write activity going on.

Deadlocks usually occur when you are writing more than one value to the same cell of the database. I was once working on an e-commerce website (running WooCommerce) with about 300 sales each hour. The big issue we were facing there was the lock happening on the database each time an update was triggered and to make things worse there was no indexing in place. The first solution therefore was to add indexing which tremendously helped. Since the index had high cardinality, it also improved our read and write performance.

After a lot more digging, the  underlying problem however was with WooCommerce Chained Products meta data.

Suppose you link a product to another parent product but later delete it, it turns out that the metadata is not properly deleted causing a null value to be called each time that particular product was purchased.

We therefore had to remove the extra post meta directly from the database and the deadlock errors have flown away.

The image used in the blog post is a result of a lot of effort by the good folks at Kinsta. Here’s a good article if you are new to WooCommerce: Kinsta’s WooCommerce tutorial

Victor Fernandes

Victor Fernandes

A friend I really respect once told me, unless you are able to dumb down a concept for someone who has no prior information about it, you can't be sure you know it yourself. I try to create blog posts that are extremely easy to understand most suitable for those in a hurry. The topics I write about include web development, digital marketing and software in general.

Leave a Reply

Contact Me

If you prefer email, you may also email me at [email protected]