Magento 1.7 Payment Deadlock Issue – Troubleshooting Guide

databasemagento-1.7payment

This is coming in an email to the client after the transaction:

Payment transaction failed.
Reason
SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

Best Answer

This comes up frequently for high-volume stores (or perhaps just high concurrency stores) from my experience. I built a (somewhat hacky) workaround and it is available on Github.

I've also discussed in other answers that the immediate retry does not solve issues because two contentious locks will always be immediately retrying. It's up to chance at that point if both make it though - and admittedly sometimes they do make it through.

My most successful patch for the deadlock issues on Magento < 1.8CE/1.13EE have been to use the same retry pattern as proposed by the now-famous Magento Forum post and instead delay the retry by successively longer periods of time. This is known as exponential backoff strategy. In the most extreme situations the customer can be forced to wait as long as 60 seconds for order completion but I have always seen locks of this nature end with successful orders and not deadlocked sessions.

For the post that gives a demo of such code see here:

https://magento.stackexchange.com/a/380/336

For the module (already mentioned by Brent) see here: https://github.com/philwinkle/Philwinkle_DeadlockRetry