Skip to content

Commit

Permalink
PqHandle rewrite to be more AMPHP compatible (and fix concurrency pro…
Browse files Browse the repository at this point in the history
…blems)
  • Loading branch information
codercms committed Oct 9, 2021
1 parent 53039f7 commit 8755101
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Driver/Pq/PqHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class PqHandle implements Handle

private int $lastUsedAt;

private string $prevSql = '';

/**
* Connection constructor.
*
Expand Down Expand Up @@ -204,6 +206,13 @@ private function send(?string $sql, callable $method, ...$args)
try {
$this->deferred = $this->busy = new Deferred;

if ($this->handle->busy) {
var_dump("WARNING: connection is busy after sql: {$this->prevSql}", $this->handle);
}
while ($this->handle->busy && $res = $this->handle->getResult()) {
var_dump('connection busy', $res);
}

$handle = $method(...$args);

// Loop::reference($this->poll);
Expand All @@ -212,6 +221,8 @@ private function send(?string $sql, callable $method, ...$args)
Event::set($this->handle->socket, null, null, SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE);
}

$this->prevSql = $sql;

$result = $this->deferred->getResult();
} catch (pq\Exception $exception) {
throw new FailureException($this->handle->errorMessage, 0, $exception);
Expand All @@ -223,12 +234,6 @@ private function send(?string $sql, callable $method, ...$args)
throw new FailureException("Unknown query result");
}

if ($this->handle->busy) {
var_dump("WARNING: connection is busy after sql: {$sql}");
var_dump($this->handle);
var_dump($result);
}

switch ($result->status) {
case pq\Result::EMPTY_QUERY:

Expand Down

0 comments on commit 8755101

Please sign in to comment.