Skip to content

Convert driver exceptions when starting transactions #6812

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

Merged

Conversation

lcobucci
Copy link
Member

Q A
Type bug

Summary

The wrapped connection may no longer be valid for long-running processes, and starting a transaction will cause driver exceptions.

DBAL Connection wasn't converting these, leaking internal details of the platform and not providing a consistent API (all other methods would throw a ConnectionLost exception for the scenario above).

This ensures we do have the expected behaviour for this edge case.

@morozov
Copy link
Member

morozov commented Feb 25, 2025

Let's get it integration-tested. Even though the unit test passes, and the code works as expected on MySQL, we want to be sure that it works the same on other platforms as well or at least know that it doesn't.

@lcobucci lcobucci force-pushed the convert-exceptions-on-begin-transaction branch 3 times, most recently from 6e47746 to 432b89d Compare February 25, 2025 23:03
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.

The code change and the tests look good. Thanks for replacing sleep() with killing the session. Just a few nits inline.

lcobucci added 4 commits March 1, 2025 21:09
This optimises how this test is executed by leveraging two connections
and killing the one executing the tests.

It also aims at making the whole conversion process available to other
platforms.

Signed-off-by: Luís Cobucci <[email protected]>
For long-running processes, it's possible that the wrapped connection is
no longer valid and starting a transaction will lead to driver
exceptions.

DBAL Connection wasn't converting these, leaking internal details of the
platform and not providing a consistent API (all other methods would
throw a `ConnectionLost` exception for the scenario above).

This ensures we do have the expected behaviour for this edge-case.

Signed-off-by: Luís Cobucci <[email protected]>
This extends the functional test for connection loss detection to verify
the behaviour against Postgres and ensures the ExceptionConverter for
that API behaves as expected.

Signed-off-by: Luís Cobucci <[email protected]>
This is required because the MySQLi API only returns a boolean result
that we were simply not using.

Signed-off-by: Luís Cobucci <[email protected]>
@lcobucci lcobucci force-pushed the convert-exceptions-on-begin-transaction branch from 432b89d to b6eb520 Compare March 1, 2025 20:12
@lcobucci lcobucci requested a review from morozov March 1, 2025 20:14
@morozov morozov merged commit 598b2a3 into doctrine:4.2.x Mar 1, 2025
66 checks passed
@morozov
Copy link
Member

morozov commented Mar 1, 2025

Thanks, @lcobucci!

@morozov morozov added this to the 4.2.3 milestone Mar 1, 2025
@lcobucci lcobucci deleted the convert-exceptions-on-begin-transaction branch March 4, 2025 10:11
@lcobucci
Copy link
Member Author

lcobucci commented Mar 6, 2025

@morozov @derrabus would it be alright to release 4.2.3 soon or are you planning to group more items under it?

@morozov
Copy link
Member

morozov commented Mar 6, 2025

I'm fine with releasing it any time.

@lcobucci
Copy link
Member Author

lcobucci commented Mar 7, 2025

I'm fine with releasing it any time.

It would be great to have it released, then

Jean85 added a commit to facile-it/doctrine-mysql-come-back that referenced this pull request Mar 13, 2025
doctrine/dbal#6812 introduced a behavioral change on lost connection. Now all drivers behave the same, and close the connection explicitly before throwing.
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.

2 participants