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

Convert driver exceptions when starting transactions #6812

Open
wants to merge 4 commits into
base: 4.2.x
Choose a base branch
from

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.

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]>
@lcobucci lcobucci force-pushed the convert-exceptions-on-begin-transaction branch from 5fa77a9 to 5c1255f Compare February 25, 2025 22:15
default => self::markTestSkipped('Unsupported test platform.'),
};

$privilegedConnection = TestUtil::getPrivilegedConnection();
Copy link
Member Author

Choose a reason for hiding this comment

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

Using priviledged connection here, assuming that's a requirement for other platforms (maybe oracle or SQL server?)


use const E_WARNING;

class TransactionTest extends FunctionalTestCase
{
public function testCommitFailure(): void
{
$this->markConnectionNotReusable();
Copy link
Member Author

Choose a reason for hiding this comment

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

Marking as not reusable as I didn't want for a failure in one test to leak into the other

Comment on lines 81 to 83
if (
$exception->getSQLState() === 'HY000'
&& str_contains($exception->getMessage(), 'server closed the connection')
) {
return new ConnectionLost($exception, $query);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This might only be applicable for recent PGSQL versions...

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah... only PDO has the SQL State set for this error :)

Ooohh I missed working with DBAL 😅

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