m6w6 / ext-pq

PostgreSQL client library (libpq) binding
BSD 2-Clause "Simplified" License
39 stars 7 forks source link

Segmentation fault after pg_terminate_backend #24

Closed uasan closed 7 years ago

uasan commented 7 years ago

Hi! This code simulates remote aborted connection, while waiting query result.

<?php

$c = new pq\Connection('user=postgres', pq\Connection::ASYNC);

$w = [$c->socket];
$r = $e = null;

if(stream_select($r, $w, $e, null))
{
    while(true)
    {
        switch($c->poll()) {
            case pq\Connection::POLLING_READING:
                $r = [$c->socket];
                stream_select($r, $w, $e, null);
                break;

            case pq\Connection::POLLING_OK:
                if($c->busy) {
                    $c->getResult();
                }
                else {
                    $c->execAsync('SELECT pg_terminate_backend(pg_backend_pid())');
                }

                break;
        }
    }
}
PHP 7.1.4 (cli) (built: Apr 11 2017 18:59:26) ( NTS )

Thank.