stomp-php icon indicating copy to clipboard operation
stomp-php copied to clipboard

Endless loop in read operation when using server heartbeat

Open danesteve opened this issue 4 years ago • 5 comments

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.

danesteve avatar Sep 16 '20 12:09 danesteve

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

jmglsn avatar Jan 15 '21 20:01 jmglsn

Hi @jmglsn, thanks for looking into this.

Yes, i can confirm that using a heartbeat > readTimeout seems to work fine.

danesteve avatar Jan 22 '21 17:01 danesteve

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.

vbkunin avatar Feb 17 '21 14:02 vbkunin

Hi @vbkunin
I also encountered similar problems. How did you solve them in the end? Thank you image

Maoxp avatar Mar 31 '21 05:03 Maoxp

Hi @Maoxp! I've rolled back to the previous version for now.

vbkunin avatar Apr 08 '21 21:04 vbkunin