Skip to content

Comments

Don't attempt to rollback when connections are lost#7240

Merged
derrabus merged 1 commit intodoctrine:4.4.xfrom
lcobucci:dont-try-to-rollback-when-connection-is-lost
Dec 4, 2025
Merged

Don't attempt to rollback when connections are lost#7240
derrabus merged 1 commit intodoctrine:4.4.xfrom
lcobucci:dont-try-to-rollback-when-connection-is-lost

Conversation

@lcobucci
Copy link
Member

@lcobucci lcobucci commented Dec 3, 2025

Q A
Type bug

Summary

It's useless to try to perform a rollback when there's no active connection, not to mention that the use of NoActiveTransaction exceptions masks the real underlying issue.

This attempts to fix the problem by detecting connection issues and bypassing rollbacks.

It's useless to try to perform a rollback when there's no active
connection, not to mention that the use of `NoActiveTransaction`
exceptions masks the real underlying issue.

This attempts to fix the problem by detecting connection issues and
bypassing rollbacks.

Signed-off-by: Luís Cobucci <[email protected]>
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

Looks good in general, just one question.

@derrabus derrabus added this to the 4.4.1 milestone Dec 3, 2025
@derrabus derrabus merged commit 3d54447 into doctrine:4.4.x Dec 4, 2025
128 checks passed
@lcobucci lcobucci deleted the dont-try-to-rollback-when-connection-is-lost branch December 4, 2025 18:19

$successful = true;
} catch (ConnectionLost $connectionLost) {
// Catching here only to be able to prevent a rollback attempt
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this dangerous when the exception is comming from another connection, ie. not rollbacking the actual transaction?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe that would be applicable to any of the captured exceptions, though.

Nevertheless, in which scenario would you imagine someone starting a transaction on the connection#1 and performing queries on the connection#2?

Copy link
Contributor

Choose a reason for hiding this comment

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

Any SQL query made on another connection (and throwing ConnectionLost exception) inside the transaction. Nothing rare. I belive the caught exception must be checked for the connection instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO it's quite odd to send SQL query to another connection inside a transaction...

If anyone need to fetch data from source A to modify stuff on source B, I'd expect only the changes in source B to happen in the transaction...

Copy link
Member Author

Choose a reason for hiding this comment

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

Nevertheless, feel free to send a PR with changes...

Copy link
Contributor

Choose a reason for hiding this comment

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

Reporting this only.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, with any other DBAL exception that we handle here, we'd have the same problem, wouldn't we?

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory yes, but a) not many functions accepts callback in critical sections, b) transaction must be robust. I pointed out a real issue and in atk4/data we already support multiple cross-DB operations, ie. my feedback is comming from existing usecase.

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