amphp / postgres

Async Postgres client for PHP based on Amp.
MIT License
97 stars 20 forks source link

Unwanted PHP Notices #23

Closed ejz closed 3 years ago

ejz commented 4 years ago
PHP Notice:  pg_send_query(): There are results on this connection. Call pg_get_result() until it returns FALSE in /var/www/vendor/amphp/postgres/src/PgSqlHandle.php on line 228

Could you mute'em, please with @? They are happened especially while working with a database pool.

kelunik commented 4 years ago

This looks like a bug to me rather than something that should be suppressed.

trowski commented 4 years ago

@Ejz Can you give me any information on the circumstances in which you saw this error?

roquie commented 4 years ago

Example code to reproduce this behavior:

use Amp\Postgres;
use Amp\Postgres\ConnectionConfig;

Amp\Loop::run(function () {
    $config = ConnectionConfig::fromString('host=localhost user=root dbname=test');

    /** @var Postgres\Pool $pool */
    $pool = Postgres\pool($config);

    yield $pool->query('SELECT * FROM generate_series(1, 999);');

    \Amp\call(function () use ($pool) {
        /** @var \Amp\Sql\Transaction $transaction */
        $transaction = yield $pool->beginTransaction();
        $transaction->query('create table if not exists testtest ();');
        $transaction->commit();
        exit;
    });
});
roquie commented 4 years ago

This error is possible to repeat without exit, maybe I'll find short example for us.

roquie commented 4 years ago

Second example:

use Amp\Postgres;
use Amp\Postgres\ConnectionConfig;
use Amp\Promise;

$config = ConnectionConfig::fromString('host=localhost user=roquie dbname=roquie');

/** @var Postgres\Pool $pool */
$pool = Postgres\pool($config);

Promise\wait($pool->query('SELECT * FROM generate_series(1, 999);'));

$promise = \Amp\call(function () use ($pool) {
    /** @var \Amp\Sql\Transaction $transaction */
    $transaction = yield $pool->beginTransaction();
    $transaction->query('create table if not exists testtest ();');
    $transaction->commit();
});

Promise\wait($promise);

$pool->close();

Workaround, – use Promise\wait(new Delayed(100)); before $pool->close();

roquie commented 4 years ago

This error happens because I forgot wait a promise in the code above :) It's not a critical issue but reserve time consuming to resolve it.

$config = ConnectionConfig::fromString('host=localhost user=roquie dbname=roquie');

/** @var Postgres\Pool $pool */
$pool = Postgres\pool($config);

Promise\wait($pool->query('SELECT * FROM generate_series(1, 999);'));

$promise = \Amp\call(function () use ($pool) {
    /** @var \Amp\Sql\Transaction $transaction */
    $transaction = yield $pool->beginTransaction();
    yield $transaction->query('create table if not exists testtest ();');
    yield $transaction->commit();
});

Promise\wait($promise);

$pool->close();