Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2 dead lock - how to handle

On a symfony2 project I'm working on sometimes dead locks occur when calling flush on my entitymanager. This results in an exception. Most of the times this error occures just once and a second attempt to insert the same data is working correctly.

Is there a good approach to execute (flush) the same transaction again. As simple

$em->flush();

won't do, since the entitymanager gets closed if an error occures.

I've found https://github.com/doctrine/doctrine2/pull/806 bit that doesn't provide a solution.

like image 414
Rene Terstegen Avatar asked May 01 '14 09:05

Rene Terstegen


1 Answers

Doctrine throws a RetryableException for this kind of error where you simply have to try it one more time to make it work.

The problem is that with Doctrine 2, those exceptions make the EntityManager unusable and you have to re-instantiate a new one.

Hopefully this will be corrected in Doctrine 3 : issue tracking

Until Doctrine 3 is released, I went with a solution that passed the test of time in production projects in my company. Everything is explained in this blog post

like image 70
La Terreur Avatar answered Oct 18 '22 01:10

La Terreur