Skip to content

Commit 22d6e2b

Browse files
committed
Handle edge reconnect cases
1 parent 7530921 commit 22d6e2b

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

  • lhc_web/ezcomponents/Database/src/handlers

lhc_web/ezcomponents/Database/src/handlers/mysql.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,25 @@ public function reconnect()
128128
} catch (Exception $e) {
129129
if ($e->errorInfo[1] == 2006 && $this->reconnectedCounter < 5) {
130130
$this->reconnectedCounter++;
131-
parent::__construct( $this->dbParams, $this->dsn );
132-
$this->query('SET NAMES \'utf8mb4\' COLLATE \'utf8mb4_unicode_ci\'');
131+
$this->reconnectClean();
133132
}
134133
}
134+
135+
// After a fork (php-resque workers), PDO may report an active
136+
// transaction on the inherited connection even though ezc's
137+
// $transactionNestingLevel was reset to 0 in the child. Force
138+
// a fresh connection to clear the stale PDO state.
139+
if ($this->inTransaction()) {
140+
$this->reconnectedCounter++;
141+
$this->reconnectClean();
142+
}
143+
}
144+
145+
private function reconnectClean()
146+
{
147+
parent::__construct( $this->dbParams, $this->dsn );
148+
$this->query('SET NAMES \'utf8mb4\' COLLATE \'utf8mb4_unicode_ci\'');
149+
$this->transactionNestingLevel = 0;
135150
}
136151

137152
/**

0 commit comments

Comments
 (0)