RabbitMQ- pika.exceptions.StreamLostError

1,664 views
Skip to first unread message

Akshay IconPro

unread,
Jan 14, 2022, 7:51:17 AM1/14/22
to rabbitmq-users
What can be done to avoid below error?
Is it a wise advice to remove heartbeat?

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/messagebroker/threaded_messagebroker.py", line 49, in _on_start
    self._rabbitMQ.consume(
  File "/usr/local/lib/python3.8/site-packages/messagebroker/messagebroker.py", line 139, in consume
    self.channel.start_consuming()
  File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 1865, in start_consuming
    self._process_data_events(time_limit=None)
  File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 2026, in _process_data_events
    self.connection.process_data_events(time_limit=time_limit)
  File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 824, in process_data_events
    self._flush_output(common_terminator)
  File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 523, in _flush_output
    raise self._closed_result.value.error
pika.exceptions.StreamLostError: Stream connection lost: ConnectionResetError(104, 'Connection reset by peer')

Wes Peng

unread,
Jan 14, 2022, 7:54:51 AM1/14/22
to rabbitm...@googlegroups.com
You should not remove heartbeats but you can increase its value if the issue is causing by it exactly.

Thanks 

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/6624469a-bcf2-4da4-be3a-96e476ca0be0n%40googlegroups.com.

Luke Bakken

unread,
Jan 14, 2022, 10:18:09 AM1/14/22
to rabbitmq-users
Hello,

Please provide the RabbitMQ logs from the time of this event. A stack trace showing a connection reset isn't that useful.

No, you should not disable heartbeats nor change their interval. My guess is the code you use to process messages is taking longer than the heartbeat interval. If you can share your code, that would help as well.

Thanks,
Luke

Leonardus Chen

unread,
Feb 1, 2022, 2:16:22 AM2/1/22
to rabbitmq-users
Hi,

```
No, you should not disable heartbeats nor change their interval. 
```

Is there a reason why changing the interval is not advisable?

If, for example, I have a scheduled job that will block Pika's I/O loop for at most 15 minutes, I can safely increase the heartbeat timeout to 15 minutes right?

Cheers,
Leonardus

Luke Bakken

unread,
Feb 1, 2022, 8:29:19 AM2/1/22
to rabbitmq-users
Hello,

Heartbeats are used to detect connection loss or other situations where communication may not be available. If you're OK with that, change the value.

The general best practice is to not block Pika's I/O loop but do work on a dedicated thread.

Thanks -
Luke
Reply all
Reply to author
Forward
0 new messages