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

Reset nested transaction level on deadlock exceptions #6103

Closed
wants to merge 3 commits into from

Conversation

tzkoshi
Copy link

@tzkoshi tzkoshi commented Jul 20, 2023

Q A
Type improvement
Fixed issues #4279.

Summary

All mysql flavors on deadlock exception rollback all transactions, thus making the internal counter in DBAL invalid.

This pull request fixes that behaviour by reseting the dbal nested transactions counter on such exceptions.

The test validates broken behaviour
with nested transactions.
@tzkoshi tzkoshi marked this pull request as ready for review July 20, 2023 06:09
$this->connection->beginTransaction();
$this->connection->executeStatement('DELETE FROM test1');

$pid = pcntl_fork();
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to fork the process? Wouldn't opening a second connection be enough to provoke a deadlock?

Copy link
Author

@tzkoshi tzkoshi Jul 20, 2023

Choose a reason for hiding this comment

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

Unfortunately, we can't as PHP is single threaded and if we attempt to simply work with two connections it just hangs till a timeout is reached. Already tried it.
Another possible solution to skip the output buffer of phpunit is to simply die in the child process, but for me it seems a bit "hacky", if that is the thing that bothers you.

$this->connection->commit();
$this->connection->commit();
} catch (DeadlockException $ex) {
self::assertFalse($this->connection->isTransactionActive());
Copy link
Member

Choose a reason for hiding this comment

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

This assertion does not tell me that the connection's transaction status is in sync with the driver.

{
parent::setUp();

$supportedDrivers = ['pdo_mysql', 'mysqli', 'pdo_pgsql'];
Copy link
Member

Choose a reason for hiding this comment

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

You said that this is an issue of MySQL drivers only, yet you're including PDO_pgsql as well. Does it make sense to exclude any drivers here? Can we come up with a driver-agnostic functional test that makes sure we can start a new transaction aftera deadlock?

Copy link
Author

@tzkoshi tzkoshi Jul 20, 2023

Choose a reason for hiding this comment

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

Only mysql/postgres of the supported drivers have deadlock exceptions. Other databases do not have such exceptions.

But, it seems that after attempting what you have suggested, to open a new transaction, this fix isn't enough and the pdo driver library must first be patched, as it stays in "active transaction state".

See the link here:
https://github.com/php/php-src/blob/b132b7ab7efb40628dedf2eae1cf7d6949684bcb/ext/pdo/pdo_dbh.c#L605

For now will postpone that pull request and willl attempt to fix firstly the php pdo driver and then will modify that PR.

Sorry for bothering you at this time.

@derrabus derrabus changed the base branch from 3.6.x to 3.7.x September 26, 2023 21:55
Copy link

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions bot added the Stale label Dec 26, 2023
Copy link

github-actions bot commented Jan 2, 2024

This pull request was closed due to inactivity.

@github-actions github-actions bot closed this Jan 2, 2024
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