Skip to content

Commit

Permalink
Fixed deadlock in getPrimaryKey method when connection error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
codercms committed Jan 27, 2021
1 parent de07372 commit f4d83a8
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Driver/MakisePostgres/PooledMakisePostgresDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,31 @@ public function getPrimaryKey(string $prefix, string $table): ?string
return $this->primaryKeys[$name];
}

if (!$this->getSchemaHandler()->hasTable($name)) {
try {
$hasTable = $this->getSchemaHandler()->hasTable($name);
} catch (\Throwable $e) {
$this->pkCacheLock->unlock();

throw $e;
}

if (!$hasTable) {
$this->pkCacheLock->unlock();

throw new DriverException(
"Unable to fetch table primary key, no such table '{$name}' exists"
);
}

$this->primaryKeys[$name] = $this->getSchemaHandler()
->getSchema($table, $prefix)
->getPrimaryKeys();
try {
$this->primaryKeys[$name] = $this->getSchemaHandler()
->getSchema($table, $prefix)
->getPrimaryKeys();
} catch (\Throwable $e) {
$this->pkCacheLock->unlock();

throw $e;
}

if (count($this->primaryKeys[$name]) === 1) {
//We do support only single primary key
Expand Down

0 comments on commit f4d83a8

Please sign in to comment.