Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected heartbeat missed exception #793

Closed
thomasvargiu opened this issue May 11, 2020 · 5 comments · Fixed by #794
Closed

Unexpected heartbeat missed exception #793

thomasvargiu opened this issue May 11, 2020 · 5 comments · Fixed by #794
Assignees
Labels

Comments

@thomasvargiu
Copy link

thomasvargiu commented May 11, 2020

Version(s) affected: 2.11.2

Description
There is a BIG problem with the heartbeat, seems that it isn't handled correctly.
This doesn't happen on v.2.11.1.

How to reproduce

<?php

require 'vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

const HEARTBEAT = 2;

$connection = new AMQPStreamConnection(
    'rabbitmq',
    5672,
    'guest',
    'guest',
    '/',
    false,
    'AMQPLAIN',
    null,
    'en_US',
    20,
    20,
    null,
    false,
    HEARTBEAT
);
$channel = $connection->channel();

$count = 0;
while (true) {
    $count++;
    echo 'Publish ' . $count . PHP_EOL;

    $channel->basic_publish(new AMQPMessage('message ' . $count), '', 'foo');
    sleep(HEARTBEAT);
}
Publish 1
Publish 2
Publish 3
PHP Fatal error:  Uncaught PhpAmqpLib\Exception\AMQPHeartbeatMissedException: Missed server heartbeat in /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/AbstractIO.php:159
Stack trace:
#0 /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php(223): PhpAmqpLib\Wire\IO\AbstractIO->checkBrokerHeartbeat()
#1 /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(381): PhpAmqpLib\Wire\IO\StreamIO->write()
#2 /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(427): PhpAmqpLib\Connection\AbstractConnection->write()
#3 /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(1159): PhpAmqpLib\Connection\AbstractConnection->send_content()
#4 /var/www/test2.php(33): PhpAmqpLib\Channel\AMQPChannel->basic_publish()
#5 {main}
  thrown in /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/AbstractIO.php on line 159
@thomasvargiu
Copy link
Author

thomasvargiu commented May 11, 2020

I think the problem is here:

https://github.com/php-amqplib/php-amqplib/pull/791/files#diff-6873441dc17d577d2115e8f622a0a33dR153-R162

We are just checking $last_read but we should also check $last_write.

I think the problem is that only publishing I'm never reading anything, so $last_read is always old.

@lukebakken lukebakken added this to the 2.11.3 milestone May 11, 2020
@lukebakken
Copy link
Collaborator

You should be reading heartbeats from the server, however. We'll look into this. I'm checking how heartbeats are implemented in other libraries, like the Java client.

@thomasvargiu
Copy link
Author

@lukebakken I tihnk other libraries are using threads to accomplish heartbeat, we can't.

@lukebakken
Copy link
Collaborator

I know that, I maintain those libraries 😄

basic_publish should take some time to read data from the socket. The problem here may be that it isn't.

@ramunasd ramunasd added the bug label May 12, 2020
@ramunasd
Copy link
Member

I will take care, thanks all.

@ramunasd ramunasd changed the title Heartbeat serious bug Unexpected heartbeat missed exception May 12, 2020
@ramunasd ramunasd removed this from the 2.11.3 milestone May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants