Server closes after pika.exceptions.StreamLostError: Stream connection lost
Asked Answered
E

3

11

I have some images in my queue and I pass each image to my flask server where processing on images is done and a response is received in my rabbitmq server. After receiving response, I get this error "pika.exceptions.StreamLostError: Stream connection lost(104,'Connection reset by peer')". This happens when rabbitmq channel again starts consuming the connection. I don't understand why this happens. Also I would like to restart the server again automatically if this error persists. Is there any way to do that?

Endodontist answered 2/7, 2019 at 19:35 Comment(1)
Please paste your code here that is generating the exception.Savadove
S
33

Your consume process is probably taking too much time to complete and send Ack/Nack to the server. Therefore, server does not receive heartbeat from your client, and thereby stops from serving. Then, on the client side you receive:

pika.exceptions.StreamLostError: Stream connection lost(104,'Connection reset by peer')

You should see server logs as well. It is probably like this:

missed heartbeats from client, timeout: 60s

See this issue for mor information.

Savadove answered 11/8, 2019 at 9:29 Comment(1)
hi, do you know why I get this error even if my consume process is not taking too much time #76172579Ladder
S
2

Do your work on another thread. See this code as an example -

https://github.com/pika/pika/blob/master/examples/basic_consumer_threaded.py

Smutty answered 4/6, 2020 at 15:10 Comment(0)
M
2

You can change stream connection limit if you set heartbeat in ConnectionParameters

connection_params = pika.ConnectionParameters(heartbeat=10)

wher number in seconds. It say yout TCP connection keepalive to 10 seconds for example.

More information https://www.rabbitmq.com/heartbeats.html and https://www.rabbitmq.com/heartbeats.html#tcp-keepalives

Masto answered 4/8, 2021 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.