Skip to content

Commit

Permalink
Add error flag in result proxy to forward connection failures to resu…
Browse files Browse the repository at this point in the history
…lt set
  • Loading branch information
trowski committed Aug 14, 2022
1 parent 7e3cada commit 9412e74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/Internal/ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ public function isReady(): bool

public function unreference(): void
{
if (!--$this->refcount) {
$this->appendTask(function () {
$this->close();
});
if (--$this->refcount || $this->isClosed()) {
return;
}

$this->sendClose()->ignore();
}

private function ready(): void
Expand Down Expand Up @@ -1066,10 +1066,7 @@ private function successfulResultFetch(): void
\assert($this->result !== null, 'Connection result was in invalid state');

$result = $this->result;
$deferred = &$result->next;
if (!$deferred) {
$deferred = new DeferredFuture;
}
$deferred = $result->next ??= new DeferredFuture();

if ($this->metadata->statusFlags & self::SERVER_MORE_RESULTS_EXISTS) {
$this->parseCallback = $this->handleQuery(...);
Expand Down Expand Up @@ -1113,10 +1110,7 @@ private function handleTextResultSetRow(string $packet): void
$fields[] = null;
$offset += 1;
} else {
$column = $this->result->columns[$i] ?? null;
if (!$column) {
throw new \RuntimeException("Definition missing for column $i");
}
$column = $this->result->columns[$i] ?? throw new \RuntimeException("Definition missing for column $i");
$fields[] = $column->type->decodeText($packet, $offset, $column->flags);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Internal/MysqlConnectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ private static function fetchRow(MysqlResultProxy $result): Future
return Future::complete();
}

if ($result->exception) {
throw $result->exception;
}

$deferred = new DeferredFuture;

/* We need to increment the internal counter, else the next time fetch is called,
Expand All @@ -99,7 +103,7 @@ public function getNextResult(): ?MysqlResult
}

$this->nextResult = async(function (): ?MysqlResult {
$deferred = $this->result->next ?: $this->result->next = new DeferredFuture;
$deferred = $this->result->next ??= new DeferredFuture;
$result = $deferred->getFuture()->await();

if ($result instanceof MysqlResultProxy) {
Expand Down
4 changes: 4 additions & 0 deletions src/Internal/MysqlResultProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ final class MysqlResultProxy

public const SINGLE_ROW_FETCH = 255;

public ?\Throwable $exception = null;

public function setColumns(int $columns): void
{
$this->columnCount = $this->columnsToFetch = $columns;
Expand Down Expand Up @@ -73,6 +75,8 @@ public function rowFetched(?array $row): void

public function error(\Throwable $e): void
{
$this->exception = $e;

foreach ($this->deferreds as $deferreds) {
foreach ($deferreds as [$deferred]) {
\assert($deferred instanceof DeferredFuture);
Expand Down

0 comments on commit 9412e74

Please sign in to comment.