dbal: MySQL + deadlock leads to `SAVEPOINT DOCTRINE_x does not exist`

Bug Report

Q A
Version any

Summary

Hello,

this issue is a follow up of https://github.com/doctrine/orm/issues/11230: in MySQL, when a deadlock occurs because of concurrency, the system tries to rollback, and then an error “SAVEPOINT DOCTRINE_x does not exist” occurs.

At first, the savepoint error did hide the original deadlock error. This has been fixed thanks to https://github.com/doctrine/orm/pull/11646 - and this will soon be fixed as well in symfony/messenger.

Nevertheless, https://github.com/doctrine/orm/issues/11230 has been closed, but the original problem is not fixed, and the rollback still fails, which results in closing the EM, and breaking the worker.

Since the dbal is the only one aware of savepoints, I think this should be fixed here.

Current behavior

When a deadlock occur, within a transaction with savepoints in MySQL, the rollback fails with SAVEPOINT DOCTRINE_x does not exist

Expected behavior

No error on roll back 😅

From MySQL doc:

When deadlock detection is enabled (the default) and a deadlock does occur, InnoDB detects the condition and rolls back one of the transactions (the victim).

So maybe when a deadlock occurs, DBAL should be resilient when the rollback fails? Or it should check the existence of the given savepoint/transaction before rolling back?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 24 (14 by maintainers)

Most upvoted comments

If a savepoint error occurs due to a deadlock, it should throw a deadlock exception. From the API consumer’s standpoint, there are no savepoints, there are nested transactions, and we need to tell all consumers that started a transaction at any level that their transaction was rolled back due to a deadlock.

So, if you’re saying that “if a deadlock occurs in a nested transaction, a DeadlockException should be thrown to the user-land”, then I think I agree.

@nikophil please provide a sample script or other instructions that will reproduce your issue. Ideally, it should use only DBAL as a dependency.

Hey @nikophil . Thank you! That indeed solves all my issues related to this. Sorry to mess up your issue.