Search code examples
pythonsocketsrabbitmqwindows-server-2012python-pika

RabbitMQ - Socket Closed Exception - Windows Server 2012


So I have a publisher which is using schedule python package to read data from a file and every 5-10 mins and publish each line to a queue. On the other side I have consumer using something like:

self.connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
self.channel = self.connection.channel()
while True:
        method, properties, body = self.channel.basic_get(queue=conf.UNIVERSAL_MESSAGE_QUEUE, no_ack=False)
        if body is not None:
            self.assign_task(body=body)
            self.channel.basic_ack(delivery_tag=method.delivery_tag)

        else:
            self.logger.info('channel empty')
            self.move_to_done()
            time.sleep(5)

Assign task function looks like:

def assign_task(body=body):
       <do something with the message body>

For some reason after a while it throws the following error:

2017-08-03 15:27:43,756: ERROR: base_connection.py: _handle_error:   335: Socket Error: 10054
2017-08-03 15:27:43,756: WARNING: base_connection.py: _check_state_on_disconnect:   180: Socket closed when connection was open
2017-08-03 15:27:43,756: WARNING: connection.py: _on_disconnect:   1360: Disconnected from RabbitMQ at localhost:5672 (0): Not specified

Essentially both publisher and consumer are 2 different python programs intended to run on a single machine with Windows Server 2012. Can community help understand what might be going wrong here.
The same code runs absolutely fine locally on my windows machine

Following is the output from my log file.
=ERROR REPORT==== 3-Aug-2017::15:06:48 === closing AMQP connection <0.617.0> ([::1]:53485 -> [::1]:5672): missed heartbeats from client, timeout: 60s


Solution

  • Simple answer to this was to create a durable queue and set heartbeat_interval to 0.