Postgres and event issue

Issue #45 wontfix
socketman2016 created an issue

I want to add read event to pg_socket with event extension both don't accept resource of pg_socket but stream_select works well

For simplicity I write test script with well known library called reactphp/event-loop

if you run test script using event extension , this warning shown and there is no read event

PHP Warning: Event::add(): Epoll ADD(1) on fd 30584288 failed. Old events were 0; read change was 1 (add); write change was 0 (none); close change was 0 (none): Bad file descriptor in vendor/react/event-loop/src/ExtEventLoop.php on line 259 PHP Warning: Event::add(): Failed adding event in vendor/react/event-loop/src/ExtEventLoop.php on line 259

Test script:

$loop = React\EventLoop\Factory::create();
$connection = pg_connect("host=localhost port=5432 dbname=mary");
$socket = pg_socket($connection);
$loop->addReadStream($socket , function (){
  echo "READ EVENT\n";
});

pg_send_query($connection , "select * from authors;");

Actual result:

PHP Warning: Event::add(): Epoll ADD(1) on fd 30584288 failed. Old events were 0; read change was 1 (add); write change was 0 (none); close change was 0 (none): Bad file descriptor in vendor/react/event-loop/src/ExtEventLoop.php on line 259 PHP Warning: Event::add(): Failed adding event in vendor/react/event-loop/src/ExtEventLoop.php on line 259

Comments (11)

  1. Ruslan Osmanov repo owner

    Is that the complete test script? I don't see how the event loop is launched, and how the socket variable is preserved until the loop finishes.

    I'm not very familiar with ReactPHP. Probably, it launches the event loop implicitly in the shutdown handler. If it's so, your $socket variable gets destroyed before the event loop tries to access it. So you should preserve all variables (such as $socket) that are supposed to be used in the event handlers until they are no longer needed.

  2. socketman2016 reporter

    Thanks for your reply

    I will send you a complete test script asap . simple and with no dependency to repro issue

  3. socketman2016 reporter

    See https://github.com/reactphp/event-loop/issues/121 , It is hard to repro issue But if you install react/event-loop with composer and run this code

    <?php
    require_once 'vendor/autoload.php';
    $loop = React\EventLoop\Factory::create();
    $connection = pg_connect("host=localhost port=5432 dbname=mary");
    $socket = pg_socket($connection);
    $loop->addReadStream($socket , function (){
      echo "READ EVENT\n";
    });
    
    pg_send_query($connection , "select * from authors;");
    $loop->run();
    

    We have Segmentation fault on PHP 7.0

  4. Ruslan Osmanov repo owner

    @Socketman2016 I will try to reproduce and fix the issue, if it is fixable from the source of Event. But I'm very busy these days, and I will not promise anything.

    Right now, I can only say that Event actually does not support postgres socket resources. Look at this function, for instance.

    As always, pull requests are welcome.

  5. Ruslan Osmanov repo owner

    I have finally tested Event with pgsql extension. As I guessed, Event extension does not support pgsql resources =) And the Event::add method rightfully returns false. However, React\EventLoop\ExtEventLoop::subscribeStreamEvent method ignores the returned value.

    I would have suggested to add support for the "PostgreSQL link" resource into Event, if pgsql had a public API for accessing the resource internals.

  6. socketman2016 reporter

    @osmanov How can I chat you?? Do you have WhatsApp account or any other way I contact you directly??

  7. Ruslan Osmanov repo owner

    @Socketman2016 You can reach me via Google Hangouts. But it's 23:20 here, so it's likely that I'll go offline very soon.

  8. Log in to comment