stomp-php
stomp-php copied to clipboard
Endless loop in read operation when using server heartbeat
After upgrading to v4.6.1 we found that our workers are caught in an endless loop when there are no messages left in the queue.
It only seems to happen when using a server heartbeat lower than the read timeout.
Here is a self contained example showcasing the issue:
<?php
require __DIR__ . '/../vendor/autoload.php';
$connection = new \Stomp\Network\Connection('tcp://127.0.0.1:61613');
$client = new \Stomp\Client($connection);
$stomp = new \Stomp\StatefulStomp($client);
$connection->setReadTimeout(10);
$client->setHeartbeat(0, 5000);
$observer = new \Stomp\Network\Observer\ServerAliveObserver();
$connection->getObservers()->addObserver($observer);
$stomp->subscribe('empty_queue');
var_dump($frame = $stomp->read());// frame will never get printed
$stomp->unsubscribe();
It seems that the issue was introduced in #137. We just downgraded to v4.6.0 for now, but using a heartbeat > readTimeout seems to work too. We are using ActiveMQ.
Regards.
Hi @danesteve, I'll check that but in general it's a good idea to set hb > than any timeout. Did that not work for your setup? BR Jens
Hi @jmglsn, thanks for looking into this.
Yes, i can confirm that using a heartbeat > readTimeout seems to work fine.
Hi @jmglsn, I found that using heartbeat > readTimeout doesn't work after 5.0.0 release. Now in this case the HeartbeatException "The server failed to send expected heartbeats" is always thrown. It seems it was introduced in https://github.com/stomp-php/stomp-php/pull/149.
I checked it with an example https://github.com/stomp-php/stomp-php-examples/blob/support/version-4/src/heartbeats_server.php with readTimeout added.
Hi @vbkunin
I also encountered similar problems. How did you solve them in the end? Thank you
Hi @Maoxp! I've rolled back to the previous version for now.