{"action":"created","issue":{"url":"https://api.github.com/repos/pika/pika/issues/564","labels_url":"https://api.github.com/repos/pika/pika/issues/564/labels{/name}","comments_url":"https://api.github.com/repos/pika/pika/issues/564/comments","events_url":"https://api.github.com/repos/pika/pika/issues/564/events","html_url":"https://github.com/pika/pika/issues/564","id":73774379,"number":564,"title":"Losing connection","user":{"login":"sulsj","id":75542,"avatar_url":"https://avatars.githubusercontent.com/u/75542?v=3","gravatar_id":"","url":"https://api.github.com/users/sulsj","html_url":"https://github.com/sulsj","followers_url":"https://api.github.com/users/sulsj/followers","following_url":"https://api.github.com/users/sulsj/following{/other_user}","gists_url":"https://api.github.com/users/sulsj/gists{/gist_id}","starred_url":"https://api.github.com/users/sulsj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sulsj/subscriptions","organizations_url":"https://api.github.com/users/sulsj/orgs","repos_url":"https://api.github.com/users/sulsj/repos","events_url":"https://api.github.com/users/sulsj/events{/privacy}","received_events_url":"https://api.github.com/users/sulsj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-05-06T23:49:11Z","updated_at":"2015-05-12T00:53:07Z","closed_at":null,"body":"Hi, \r\n\r\nI'm using 0.9.14 version pika on RabbitMQ  3.1.5. My application has a client which distributes a set of tasks so that many workers process the tasks. The issue I've been seeing for a long time is the worker always lose it's connection esp. when there are multiple workers are running. Please let me know if this has already been discussed. Here comes the code and the trace. \r\n\r\nThanks, \r\nSeung\r\n\r\n---\r\n```\r\ndef on_request(ch, method, props, body):\r\n    ...\r\n    log.info(\"Return queue name = %s\", props.reply_to)\r\n    ch.basic_publish(exchange='', \r\n\t routing_key=props.reply_to, \r\n\t properties=pika.BasicProperties(\r\n   \t    delivery_mode = 2,\r\n\t    correlation_id = props.correlation_id),\r\n\t    body=response)\r\n   \r\n    logger.info(\"Sent the result back to the client via '%s' queue.\" % (props.reply_to))\r\n    ch.basic_ack(delivery_tag=method.delivery_tag)\r\n\t\r\n...\r\n\r\ndef main(argv):\r\n    ...\r\n    ch.basic_qos(prefetch_count=1)\r\n    ch.basic_consume(on_request, queue=taskQueueName, no_ack=False)\r\n    ch.start_consuming()\r\n    ...\r\n```\r\n\r\n\r\n2015-05-06 12:29:34,029 | tfmq-worker | on_request | DEBUG : Return queue name =  after_20150201.csv.tfmq.task.lst_RESULT_QUEUE\r\n Traceback (most recent call last):\r\n  File \"/.../tfmq-worker\", line 555, in <module>\r\n    sys.exit(main(sys.argv))\r\n  File \"/.../tfmq-worker\", line 545, in main\r\n    ch.start_consuming()\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 955, in start_consuming\r\n    self.connection.process_data_events()\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 240, in process_data_events\r\n    if self._handle_read():\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 348, in _handle_read\r\n    super(BlockingConnection, self)._handle_read()\r\n  File \"/.../python2.7/site-packages/pika/adapters/base_connection.py\", line 351, in _handle_read\r\n    self._on_data_available(data)\r\n  File \"/.../python2.7/site-packages/pika/connection.py\", line 1285, in _on_data_available\r\n    self._process_frame(frame_value)\r\n  File \"/.../python2.7/site-packages/pika/connection.py\", line 1365, in _process_frame\r\n    self._deliver_frame_to_channel(frame_value)\r\n  File \"/.../python2.7/site-packages/pika/connection.py\", line 976, in _deliver_frame_to_channel\r\n    return self._channels[value.channel_number]._handle_content_frame(value)\r\n  File \"/.../python2.7/site-packages/pika/channel.py\", line 792, in _handle_content_frame\r\n    self._on_deliver(*response)\r\n  File \"/.../python2.7/site-packages/pika/channel.py\", line 886, in _on_deliver\r\n    body)\r\n  File \"/somewhere/tfmq-worker\", line 191, in on_request\r\n    body=response)\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 572, in basic_publish\r\n    (properties, body), False)\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 1159, in _send_method\r\n    self.connection.send_method(self.channel_number, method_frame, content)\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 274, in send_method\r\n    self._send_method(channel_number, method_frame, content)\r\n  File \"/.../python2.7/site-packages/pika/connection.py\", line 1503, in _send_method\r\n    self._send_frame(frame.Method(channel_number, method_frame))\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 417, in _send_frame\r\n    super(BlockingConnection, self)._send_frame(frame_value)\r\n  File \"/.../python2.7/site-packages/pika/connection.py\", line 1490, in _send_frame\r\n    self._flush_outbound()\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 377, in _flush_outbound\r\n    if self._handle_write():\r\n  File \"/.../python2.7/site-packages/pika/adapters/base_connection.py\", line 365, in _handle_write\r\n    return self._handle_error(error)\r\n  File \"/.../python2.7/site-packages/pika/adapters/base_connection.py\", line 302, in _handle_error\r\n    self._handle_disconnect()\r\n  File \"/.../python2.7/site-packages/pika/adapters/base_connection.py\", line 248, in _handle_disconnect\r\n    self._adapter_disconnect()\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 318, in _adapter_disconnect\r\n    self._check_state_on_disconnect()\r\n  File \"/.../python2.7/site-packages/pika/adapters/blocking_connection.py\", line 371, in _check_state_on_disconnect\r\n    raise exceptions.ConnectionClosed()\r\npika.exceptions.ConnectionClosed"},"comment":{"url":"https://api.github.com/repos/pika/pika/issues/comments/101083917","html_url":"https://github.com/pika/pika/issues/564#issuecomment-101083917","issue_url":"https://api.github.com/repos/pika/pika/issues/564","id":101083917,"user":{"login":"vitaly-krugl","id":1441066,"avatar_url":"https://avatars.githubusercontent.com/u/1441066?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-krugl","html_url":"https://github.com/vitaly-krugl","followers_url":"https://api.github.com/users/vitaly-krugl/followers","following_url":"https://api.github.com/users/vitaly-krugl/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-krugl/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-krugl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-krugl/subscriptions","organizations_url":"https://api.github.com/users/vitaly-krugl/orgs","repos_url":"https://api.github.com/users/vitaly-krugl/repos","events_url":"https://api.github.com/users/vitaly-krugl/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-krugl/received_events","type":"User","site_admin":false},"created_at":"2015-05-12T00:53:07Z","updated_at":"2015-05-12T00:53:07Z","body":"@sulsj, BlockingConnection won't do any hearbeat processing on its own, since it doesn't have its own thread of execution. Its I/O loop runs only when you make a call that requires I/O. I believe that the recommended way to keep things alive is to make periodic calls to the connection's `process_data_events()` method (see http://pika.readthedocs.org/en/latest/modules/adapters/blocking.html).\r\n\r\nThat said, your app needs to be prepared to deal with connection loss. I am not aware of any 100% effective method to keep the connection alive with any client. And even if it's not the client, then it could be the server that gets restarted, causing connections to be dropped."}}