Doctrine2 dead lock - how to handle

In the symfony2 project I'm working on, deadlocks sometimes occur when flush called on my noun. This leads to an exception. In most cases, this error occurs only once, and a second attempt to insert the same data works correctly.

Is there a good approach to doing (resetting) the same transaction again. How simple

 $em->flush(); 

will not be executed because the entitymanager closes if an error occurs.

I found a https://github.com/doctrine/doctrine2/pull/806 bit which does not provide a solution.

+8
mysql deadlock doctrine2
source share
1 answer

I would use explicit transaction demarcation to hopefully prevent a deadlock in the first place. By default, only a flush() transaction ends with a transaction.

Alternatively, you can change your procedure to use a DQL UPDATE query, which should be atomic.

Or resubmit the request back to the action (with some recursion limit).

I'm not sure that there will be a good way to restart the entity manager, but save the unit of work.

0
source share

All Articles