Automatic InnoDB deadlocks retry

Hi

As application grows and traffic scales up we observe some increase in InnoDB deadlocks rate like this:


Database Exception – yii\db\Exception

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

The SQL being executed was: INSERT INTO `token` (`type`, `user_id`, `created_at`, `code`) VALUES (0, 23976, 1512392365, 'IDGDVci8FiZC_2S1g6Y-Vuk4WLSTVG4t')


Error Info: Array

(

    [0] => 40001

    [1] => 1213

    [2] => Deadlock found when trying to get lock; try restarting transaction

)


↵

Caused by: PDOException

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


in /home/****/vendor/yiisoft/yii2/db/Command.php at line 994

As you see - some of them are observed withing third-party extensions what effectively blocks simple resolution.

I propose to enhance PDO Adapter so it could handle deadlocks gently in a similar manner like here:

https://www.npmjs.com/package/node-mysql-deadlock-retries

You may see this in Magento as well:

How do you see this?

@Samdark, @Cebe, @Paul Klimov?

Sounds OK. Do you want to propose it via GitHub pull request?

I could work on it on Christmas. Indeed - I could submit my result via pull request - why not? I will be in touch then!

Thank you, Alexandr.