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

fix_begin_transaction_after_reconnect #3680

Closed
wants to merge 1 commit into from

Conversation

kalinin-k-a
Copy link
Contributor

@kalinin-k-a kalinin-k-a commented Sep 20, 2019

Q A
Type bug
BC Break no
Fixed issues

Summary

This is a small fix if we lose the connection and work with transactions after reconnect.
The code examples below demonstrate a problem:
/** Doctrine\DBAL\Connection $co /
This is a small fix if we lose the connection and work with transactions after reconnect.
The code examples below demonstrate a problem:
/
* Doctrine\DBAL\Connection $co /
$co->executeQuery('CREATE TABLE if not exists test11(test int not null)');
$co->executeQuery('truncate table test11');
$co->executeQuery('insert into test11 values (1)');
$co->beginTransaction();
$co->executeQuery('insert into test11 values (2)');
$v = $co->fetchAll('select * from test11');
$co->close(); // here we lost a connection or closed it for some reason
$co->beginTransaction(); /
p1 /
$co->executeQuery('insert into test11 values (33)');
$co->rollback(); /
p2 */
$v = $co->fetchAll('select * from test11'); // I expect the value 33 will not be selected from the table because it was rollbacked. But the transaction was not started on the line "p1" because of nestingLevel had not beed reset after open new connection.

When the connection is lost, subsequent transactions will no longer be
nested because they are executed in a brand new session. Our internal
representation of the nesting should take this into account.
@SenseException
Copy link
Member

I'm not sure if I understand the problem for this solution. What is responsible for closing the connection? It looks like this fix is for a human created problem. Can you please elaborate the use case more?

Also: DBAL 2.5 isn't supported anymore. Please target the master branch for your PR.

@morozov
Copy link
Member

morozov commented Sep 24, 2019

What is responsible for closing the connection?

@SenseException this is a good question. As far as I understand, the connection may be lost due to external factors and then something reestablishes it. However, I'm not sure that DBAL can reconnect automatically. E.g. this is why one could do Connection::ping() manually.

@kalinin-k-a
Copy link
Contributor Author

Also: DBAL 2.5 isn't supported anymore. Please target the master branch for your PR.

Ok, I close it. There is another request into master.

I'm not sure if I understand the problem for this solution. What is responsible for closing the connection? It looks like this fix is for a human created problem. Can you please elaborate the use case more?

More detailed usecase can be described as code below

$attempts = 5;
while ($attempts--) {
  try {
    return $connection->fetcAll($query); 
  catch (DBALException $e) {
    if ($connection->errorCode() === 2006) { // gone away
        $connection->close();
    }
  }
}

and if nested level was not 0, than Connection object still think that it is still in transaction even after I call close().

@SenseException
Copy link
Member

I'll close this PR in favor of your new PR #3679. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants