Skip to content

[Messenger] Swallow Exception on Rollback #54355

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

rodnaph
Copy link
Contributor

@rodnaph rodnaph commented Mar 20, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? no
Deprecations? no
Issues None
License MIT

When a database level exception occurs, eg. constraint violations, it may not be possible to rollback the active transaction when handing the exception in the Messenger middleware. In this case an exception is thrown from rollback, and the original exception is lost.

I've added a try/catch to swallow any exception rolling back, so the original exception will be thrown as expected. I don't know if there is better behaviour here, just swallowing the exception seems quite poor. We could create a new exception with the rollback error, adding the original exception to it?

I also tried checking if there was an active transaction before rolling back, but that does not seem to be a reliable method for catching this condition.

I've marked this as neither a bugfix or a feature... it's a minor improvement, but let me know if I should update the description.

if there is an exception rolling back the transaction then the original
exception will be hidden.
@rodnaph rodnaph force-pushed the messenger-transaction-exception branch from d468c1a to d0619ba Compare March 20, 2024 15:57
@rodnaph rodnaph changed the title [Messenger] Only Rollback When Active Transaction [Messenger] Swallow Exception on Rollback Mar 20, 2024
$entityManager->getConnection()->rollBack();
try {
$entityManager->getConnection()->rollBack();
} catch (\Throwable $e) {
Copy link
Contributor Author

@rodnaph rodnaph Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (\Throwable $e) {
} catch (\Throwable $e) {
$exception = new \Exception($e->getMessage(), $e->getCode(), $exception);

Is it better to pass along some notification of rollback failure? This will interfere with the check a few lines below though, so would need to be structured differently.

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@rodnaph
Copy link
Contributor Author

rodnaph commented Jun 17, 2024

Similar issue: doctrine/orm#7545

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants