10

I'm using the RabbitMQ Library videlalvaro/php-amqplib inside a Laravel 4.2 application and I've started getting the following error:

fwrite(): send of 12 bytes failed with errno=104 Connection reset by peer"

Can anyone suggest anything that might be causing this?

Mark Biek
  • 146,731
  • 54
  • 156
  • 201
Marwan
  • 1,802
  • 2
  • 17
  • 22

4 Answers4

5

"Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the hook. It's more polite than merely not replying, leaving one hanging. But it's not the FIN-ACK expected of the truly polite TCP/IP converseur. (From other SO answer)

So you can't do anything about it, it is the issue of the server.

But you could use try .. catch block to handle that exception:

try {
    $msg = new AMQPMessage('Hello World!');
    $channel->basic_publish($msg, '', 'hello');

} catch (Exception $e) {
    // handle exception
}
Community
  • 1
  • 1
Limon Monte
  • 52,539
  • 45
  • 182
  • 213
3

I had the same issue. Setting prefetch count to 1 is working for me as I don't care little performance tradeoff with stability.

$channel->basic_qos(0, 1, false);

syntax:

basic_qos($prefetch_size, $prefetch_count, $a_global);
Kush
  • 755
  • 7
  • 22
0

I had same problem. This case could resolved this problem. You should call this method in your method 'execute' in ClassNameConsumer class.

For php lang.

/**
 * Resolved problem - Connection reset by peer
 * @param AMQPMessage $msg
 */
public function keepAlive(AMQPMessage $msg)
{
    if (!isset($this->message->delivery_info['channel'])) {
        return;
    }

    /** @var AMQPChannel $channel */
    $channel = $msg->delivery_info['channel'];

    $pkt = new AMQPWriter();
    $pkt->write_octet(8);
    $pkt->write_short(0);
    $pkt->write_long(0);
    $pkt->write_octet(0xCE);

    $channel->getConnection()->write($pkt->getvalue());
}
0

In my case I am using the php-amqplib/rabbitmq-bundle on a Symfony project, I was getting the error 'Connection reset by peer' very often, the problem was related to the prefetch size, so by limiting the prefetch size I got rid of this error.

On the consumer configuration you need to add the line below:

qos_options: {prefetch_size: 0, prefetch_count: 1, global: false}

You will have something like this:

consumers:
    consumer_name:
        connection:       default
        exchange_options: {name: 'consumer-name', type: direct}
        queue_options:    {name: 'consumer-name'}
        callback:         consumer_name_service
        qos_options:      {prefetch_size: 0, prefetch_count: 1, global: false}
Dharman
  • 30,962
  • 25
  • 85
  • 135