Pool hangs for unknown reason
prolic opened this issue · 4 comments
I have a method like this (simplified here):
protected function doRead(): Generator
{
try {
$this->logger->debug('do request events from ' . $this->fromSequenceNumber); // stops after the log entry
$sql = <<<SQL
SELECT
COALESCE(e1.event_id, e2.event_id) as event_id,
e1.event_number as event_number,
COALESCE(e1.event_type, e2.event_type) as event_type,
COALESCE(e1.data, e2.data) as data,
COALESCE(e1.meta_data, e2.meta_data) as meta_data,
COALESCE(e1.is_json, e2.is_json) as is_json,
COALESCE(e1.updated, e2.updated) as updated
FROM
events e1
LEFT JOIN events e2
ON (e1.link_to = e2.event_id)
WHERE e1.stream_id = ?
AND e1.event_number >= ?
ORDER BY e1.event_number ASC
LIMIT ?
SQL;
/** @var Statement $statement */
$statement = yield $this->pool->prepare($sql);
$this->logger->debug('executing fetch query'); // never gets logged
/** @var ResultSet $result */
$result = yield $statement->execute([$this->streamId, $this->fromSequenceNumber, self::MaxReads]);
$readEvents = 0;
while (yield $result->advance(ResultSet::FETCH_OBJECT)) {
$this->logger->debug('found event, enqueue');
$row = $result->getCurrent();
$this->logger->debug(json_encode($row));
++$readEvents;
$this->fromSequenceNumber = $row->event_number + 1;
}
if (0 === $readEvents && $this->stopOnEof) {
$this->logger->debug('stopped');
$this->stopped = true;
}
} catch (\Throwable $e) {
$this->logger->error($e->getMessage());
$this->logger->error($e->getTraceAsString());
}
}
When I first call this method, it works, on a second call, it stops at [2018-05-19 19:08:00] PROJECTOR-testlinkto.DEBUG: do request events from 401 [] []
(see comments in code above). There is no error logged, so try-catch didn't do any difference. I debugged the connection pool, I have 100 max connections and 2 are used and both idle, so that's also not the problem. I can't tell what's going on at the moment.
Any help is greatly appreciated.
I think this has nothing to do with amphp/postgres, but due to some (still unknown) reasons, the php process (I'm using amphp/parallel for this) dies with nothing in error_log.
Maybe out of memory?
@kelunik I found the root cause now. I had code similar to this somewhere:
public function doSomething(): void
{
$promise = $this->doSomethingElse();
wait($promise); // @todo refactor
}
This somehow caused the event loop to cancel and the application was finished. I don't know why, but after I refactored this part, there was no problem anymore.