Search code examples
pythonwebsocketrabbitmqtornadopika

CRITICAL:pika.connection:Attempted to send frame when closed


I have used Pika to integrate the Websocket in Tornado and RabbitMQ. It sucessfully runs on various queues till some time. Then raises the following error:

CRITICAL:pika.connection:Attempted to send frame when closed

I have taken the code reference from https://github.com/haridas/RabbitChat/blob/master/tornado_webapp/rabbit_chat.py

I have gone through my code thoroughly, however fail to understand why it raises such an error. Can someone help troubleshoot!

Thanks!

Also note changing the backpressure multiplier does not solve the problem. So looking for a real solution for this one.


Solution

  • Since the consumers and producers were queuing - dequeuing from a particular queue, at a point PIKA Client just choked out due to the multiple asynchronous threading systems over the shared queue.

    Thus, in case anybody else faces the same issue follow the several check ups in your code:

    1. How many connections are you having? How many channels? how many queues? How many producers- consumers? (These could be determined by the sudo rabbitmqctl list_queues etc )

    2. Once you understand the structure you are using, track the running transactions. For several requests by several users.

    3. Thus on each transaction, print the thread action, so that you understand the pika activities. Since these threads run in async, if overwhelmed wrongly, causes the pika client to crash. Thus create a Thread Manager to control the threads.

    Solution was advised by Gavin Roy & Michael Klishin, from Pika & RabbitMQ respectively.