question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BlockingConnection hearbeat

See original GitHub issue

Hello, I need your help. Cannot figure out solution. I’m using Rabbitmq docker container with my python app.

About 10 min after running I having exception in my app:

pika.exceptions.ConnectionClosed: (-1, 'EOF')

Following log in rabbitmq docker:

2018-05-27 11:05:25.296 [warning] <0.1795.0> closing AMQP connection <0.1795.0> (172.18.0.1:58040 -> 172.18.0.2:5672):
missed heartbeats from client, timeout: 60s

Here is my producer code:

class Producer(object):
    EXCHANGE_TYPE = "direct"
    EXCHANGE_DURABLE = True

    def __init__(self, url, exchange):
        self._connection = pika.BlockingConnection(pika.URLParameters(url))
        self._channel = self._connection.channel()

        self._exchange = exchange
        self._channel.exchange_declare(
            exchange=self._exchange,
            exchange_type=self.EXCHANGE_TYPE,
            durable=self.EXCHANGE_DURABLE
        )

    def publish(self, route, data):
        self._channel.basic_publish(exchange=self._exchange, routing_key=route, body=data)

    def close(self):
            self._channel.close()
            self._connection.close()

url = ‘amqp://guest:guest@’+ args.rmq +‘:5672/%2F?heartbeat=0’ exchange = “my_exchange”

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
lukebakkencommented, Jun 4, 2018

@farrukh-okhunov I am able to reproduce what you describe without using docker.

Please see the changes I made in this commit which shows how to ensure heartbeats are processed while using BlockingConnection.

In your code, you should enable heartbeats, and use process_data_events() periodically to ensure they are processed. Or, you could use the asynchronous publisher code here as a starting point, as it will periodically send heartbeats.

Here is a summary of what I think is affecting you:

  • You attempt to disable heartbeats but they are not actually disabled due to the bug described in #1014. This is fixed in 0.12.0b3, so I would like you to test with that version.
  • Rather than disabling heartbeats, you should either use SelectConnection or modify your code in a manner to what I have done here to ensure that heartbeats are processed.
  • You did not see this issue using the golang code as it will process heartbeats asynchronously by default.

I am going to close this issue now but please feel free to comment and re-open it if you have further questions or find something new. Thanks again for patiently providing the information I requested.

1reaction
lukebakkencommented, May 30, 2018

Thanks for providing all that information. This issue may be related to #1055.

I tried to run my script with RabbitMQ which is not in Docker container. Result: everything works well.

Fixing issues that only arise in docker are not as high priority as other issues. I suggest searching docker issues or the internet for other abrupt connection closure issues - maybe there is a docker setting that needs to be adjusted?

Just as a reminder, Pika is maintained by volunteers on their spare time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ensuring well-behaved connection with heartbeat and ... - Pika
A blocked connection may last for an indefinite period of time, stalling the connection and possibly resulting in a hang (e.g., in BlockingConnection)...
Read more >
Keep pika BlockingConnection alive without disabling heartbeat
The only solution is to send heartbeat frames periodically. When using a BlockingConnection , you have to call the process_data_events ...
Read more >
Impossible to disable heartbeats with BlockingConnection #965
However when trying to set heartbeat=0 in the ConnectionParameters, the server value is always respected. Example code to reproduce with default ...
Read more >
Detecting Dead TCP Connections with Heartbeats ... - RabbitMQ
The heartbeat timeout value defines after what period of time the peer TCP connection should be considered unreachable (down) by RabbitMQ and client...
Read more >
Heartbeat with BlockingConnection - Google Groups
I'm trying out heartbeat with BlockingConnection. · This is the code for the connection: · params = ConnectionParameters(host=self. · self. · After connecting,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found