mirror of
https://github.com/doctrine/orm.git
synced 2026-04-29 09:23:20 +02:00
When a RetryableException is thrown, entitymanager should not be closed #5404
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kcassam on GitHub (Feb 1, 2017).
When a RetryableException is thrown, entitymanager should not be closed
The "bad" code is here : https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L400
RetryableException are DeadlockException and LockWaitTimeoutException
entitymanager should not be closed so we can retry the flush like that
@jaikdean commented on GitHub (Aug 9, 2019):
Is there a good approach to retrying after deadlocks in the meantime?
@tinpansoul commented on GitHub (Oct 11, 2019):
Is there any "at least not so bad" and simple/quick solution before v3.x release?
For example, i have
mergein loop and then make oneflushwith hundreds entities. But if there is any exception inside of loop – a lot of changes inside loop are lost with log flooded by "EntityManager is closed". That's annoying.Any solutions can be done here now except making
flush/resetinside of loop (super bad idea) or level down todetachfrom orm and use raw dbal/sql queries?@SenseException commented on GitHub (Oct 15, 2019):
Approaches were mentioned in #865, but it still will be an entity manager without persisted entities.
@dvdknaap commented on GitHub (Oct 6, 2021):
Is there already someone that found a solutions for this because impossible to retry it even when you reset the manager ?
The only solution is to do the full request again in rabbitMQ till it's working.
@rixafy commented on GitHub (Feb 23, 2025):
I wrote entity manager that can do this https://gist.github.com/Rixafy/82d96712cf1f87ce26ce052ced2eba78.
I did it by copying UnitOfWork before flush() or wrapInTransaction is called on real EM, then when RetryableException is thrown, I'll check if EM is closed, and if it is, I'll reopen it using reflection and set the original copy of UnitOfWork, because closing EM also cleared unit of work state, so far it's working alright, I had 2 deadlocks today and both succeeded on 2. attempt.