-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache][HttpFoundation][Lock] Fix PDO store not creating table + add tests #52459
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,7 @@ public function save(Key $key) | |
try { | ||
$stmt = $conn->prepare($sql); | ||
} catch (\PDOException $e) { | ||
if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) { | ||
if ($this->isTableMissing($e) && (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true))) { | ||
$this->createTable(); | ||
} | ||
$stmt = $conn->prepare($sql); | ||
|
@@ -127,8 +127,18 @@ public function save(Key $key) | |
try { | ||
$stmt->execute(); | ||
} catch (\PDOException $e) { | ||
// the lock is already acquired. It could be us. Let's try to put off. | ||
$this->putOffExpiration($key, $this->initialTtl); | ||
if ($this->isTableMissing($e) && (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes indeed, also in DoctrineDbalAdapter, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The DBAL adapter catches TableNotFoundException so it is already fine (and the DBAL adapter uses the DBAL API that does the preparation and the execution internally so the try/catch wraps both). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the try/catch is around the call to prepare, not to execute, that's why I'm wondering There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added the logic to |
||
$this->createTable(); | ||
|
||
try { | ||
$stmt->execute(); | ||
} catch (\PDOException $e) { | ||
$this->putOffExpiration($key, $this->initialTtl); | ||
} | ||
} else { | ||
// the lock is already acquired. It could be us. Let's try to put off. | ||
$this->putOffExpiration($key, $this->initialTtl); | ||
} | ||
} | ||
|
||
$this->randomlyPrune(); | ||
|
@@ -316,4 +326,21 @@ private function getCurrentTimestampStatement(): string | |
return (string) time(); | ||
} | ||
} | ||
|
||
private function isTableMissing(\PDOException $exception): bool | ||
{ | ||
$driver = $this->getDriver(); | ||
$code = $exception->getCode(); | ||
|
||
switch (true) { | ||
case 'pgsql' === $driver && '42P01' === $code: | ||
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'): | ||
case 'oci' === $driver && 942 === $code: | ||
case 'sqlsrv' === $driver && 208 === $code: | ||
case 'mysql' === $driver && 1146 === $code: | ||
Comment on lines
+335
to
+340
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taken from Doctrine. |
||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.