friends-of-reactphp / stomp

STOMP bindings for ReactPHP.
MIT License
115 stars 42 forks source link

Server disconnection are not detected #24

Open romainneutron opened 11 years ago

romainneutron commented 11 years ago

For example, run php examples/publish.php rabbitmq, shutdown Rabbit MQ server, see that it continues to send frames, no exception thrown

romainneutron commented 11 years ago

There is currently no way to prevent this. Heartbeat or receipt could improve this

romainneutron commented 11 years ago

It appears that React\Stream\Buffer does not catch an error on fwrite call.

I added an exit (that is never reached when I shutdown RabbitMQ) in React\Stream\Buffer at line 94 like this :

        if (false === $sent) {
            exit('tadaaa');
            $this->emit('error', array(new \ErrorException(
                $this->lastError['message'],
                0,
                $this->lastError['number'],
                $this->lastError['file'],
                $this->lastError['line']
            )));

            return;
        }

Is it a know issue @igorw ?

igorw commented 11 years ago

This issue is new to me. But @cboden mentioned a similar issue related to libev and libuv loops. Which loop are you using?

romainneutron commented 11 years ago

I'm using libevent

romainneutron commented 11 years ago

The error can be reproduced with a simple script :

$fd = stream_socket_client('tcp://localhost:61613', $errno, $errstr);
stream_set_blocking($fd, 0);
$initialized = false;

fwrite($fd, "CONNECT\naccept-version:1.1\nhost:/\nlogin:guest\npasscode:guest\n\n\x00");

while (true) {
    $read = fread($fd, 1024);

    if ($read) {
        echo "Read : $read\n";

        if (0 === strpos($read, "CONNECTED\n")) {
            $initialized = true;
            echo "Initialized !\n";
        }
    }

    if ($initialized) {
        echo "Sending frame...\n";
        fwrite($fd, "SEND\ndestination:/topic/foo\ncontent-length:10\ncontent-type:text/plain\n\nle message\x00");
        usleep(500000);
    }
}

when running this script and shutdown RabbitMQ produces :

➜  react-stomp git:(master) ✗ php test-stream.php
Read : CONNECTED
session:session-gzyp_Sp1VOjbI9u9wDK5yw
heart-beat:0,0
server:RabbitMQ/3.0.4
version:1.1

Initialized !
Sending frame...
Sending frame...
Sending frame...
Sending frame...
PHP Notice:  fwrite(): send of 82 bytes failed with errno=32 Broken pipe in /Users/romain/Documents/workspace/react-stomp/test-stream.php on line 24
PHP Stack trace:
PHP   1. {main}() /Users/romain/Documents/workspace/react-stomp/test-stream.php:0
PHP   2. fwrite() /Users/romain/Documents/workspace/react-stomp/test-stream.php:24