Skip to content

Commit d4bfeab

Browse files
author
k.kalinin
committed
Reset transaction nesting level on connection loss
When the connection is lost or is closed, subsequent transaction will no longer be nested because they started in a brand new session. Our internal representation of the nesting shold take this into account
1 parent b0726e7 commit d4bfeab

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/Doctrine/DBAL/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ public function connect()
354354
$this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions);
355355
$this->isConnected = true;
356356

357+
$this->transactionNestingLevel = 0;
358+
357359
if ($this->autoCommit === false) {
358360
$this->beginTransaction();
359361
}

tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ public function testTransactionNestingBehavior() : void
7272
}
7373
}
7474

75+
public function testTransactionNestingLevelIsResetOnReconnect() : void
76+
{
77+
$this->connection->beginTransaction();
78+
$this->connection->beginTransaction();
79+
self::assertEquals(2, $this->connection->getTransactionNestingLevel());
80+
$this->connection->close(); // connection is lost
81+
$this->connection->beginTransaction(); // should connect, reset nesting level and increase it once
82+
self::assertEquals(1, $this->connection->getTransactionNestingLevel());
83+
$this->connection->commit();
84+
self::assertEquals(0, $this->connection->getTransactionNestingLevel());
85+
}
86+
7587
public function testTransactionNestingBehaviorWithSavepoints() : void
7688
{
7789
if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) {

0 commit comments

Comments
 (0)