Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a RetryableException is thrown, entitymanager should not be closed #6272

Open
kcassam opened this issue Feb 1, 2017 · 4 comments
Open
Milestone

Comments

@kcassam
Copy link
Contributor

kcassam commented 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

/*
    * Since doctrine 2.6, you cannot retry a flush when an exception had appeared 
    * because the entity manager is closed and all entities detach, even with a RetryableException. 
    * This function won't work, bescause if there is an Exception, the em is closed. 

    private retryflush() {

        $retry = 0;
        while ($retry < 3) {
            try {
                $this->em->flush();
                return;
            } catch (RetryableException $e) {
                
                if ($retry >= 2) {
                    throw $e;
                }
                sleep(1);
                $this->reset();
                $retry++;
            } 
        }
    }
*/

@jaikdean
Copy link

jaikdean commented Aug 9, 2019

Is there a good approach to retrying after deadlocks in the meantime?

@trogwarz
Copy link

trogwarz commented Oct 11, 2019

Is there any "at least not so bad" and simple/quick solution before v3.x release?

For example, i have merge in loop and then make one flush with 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/reset inside of loop (super bad idea) or level down to detach from orm and use raw dbal/sql queries?

@SenseException
Copy link
Member

Approaches were mentioned in #865, but it still will be an entity manager without persisted entities.

NoelLH added a commit to thebiggive/matchbot that referenced this issue Nov 16, 2019
…able edge case deadlocks and slow locks

Simply retrying doesn't work in Doctrine 2.x because it destroys the EntityManager before throwing
'retryable' exceptions. See doctrine/orm#6272 and
https://medium.com/lebouchondigital/thread-safe-business-logic-with-doctrine-f09c633f6554
@dvdknaap
Copy link

dvdknaap commented 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.

@derrabus derrabus modified the milestones: 3.0.0, 4.0.0 May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants