Skip to content

Commit

Permalink
Reset transaction nesting level on connection loss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
k.kalinin committed Sep 21, 2019
1 parent de23082 commit c16b613
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ public function connect()
$this->_params['password'] : null;

$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);

$this->_transactionNestingLevel = 0;
$this->_isConnected = true;

if (null === $this->platform) {
Expand Down
12 changes: 12 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public function testTransactionNestingBehavior()
}
}

public function testTransactionNestingLevelIsResetOnReconnect()
{
$this->connection->beginTransaction();
$this->connection->beginTransaction();
self::assertEquals(2, $this->connection->getTransactionNestingLevel());
$this->connection->close(); // connection is lost
$this->connection->beginTransaction(); // should connect, reset nesting level and increase it once
self::assertEquals(1, $this->connection->getTransactionNestingLevel());
$this->connection->commit();
self::assertEquals(0, $this->connection->getTransactionNestingLevel());
}

public function testTransactionNestingBehaviorWithSavepoints()
{
if (!$this->_conn->getDatabasePlatform()->supportsSavepoints()) {
Expand Down

0 comments on commit c16b613

Please sign in to comment.