Skip to content

Commit

Permalink
Merge pull request #7 from makise-co/feature/fix-get-pk-deadlock
Browse files Browse the repository at this point in the history
Fixed deadlock in getPrimaryKey method when connection error occurs
  • Loading branch information
codercms authored Jan 27, 2021
2 parents de07372 + f4d83a8 commit 4874467
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 4874467

Please sign in to comment.