{"action":"created","issue":{"url":"https://api.github.com/repos/celery/celery/issues/3338","repository_url":"https://api.github.com/repos/celery/celery","labels_url":"https://api.github.com/repos/celery/celery/issues/3338/labels{/name}","comments_url":"https://api.github.com/repos/celery/celery/issues/3338/comments","events_url":"https://api.github.com/repos/celery/celery/issues/3338/events","html_url":"https://github.com/celery/celery/issues/3338","id":167274728,"number":3338,"title":"Makes heartbeat check possible for sync loop when socket timeout","user":{"login":"air-upc","id":14231765,"avatar_url":"https://avatars.githubusercontent.com/u/14231765?v=3","gravatar_id":"","url":"https://api.github.com/users/air-upc","html_url":"https://github.com/air-upc","followers_url":"https://api.github.com/users/air-upc/followers","following_url":"https://api.github.com/users/air-upc/following{/other_user}","gists_url":"https://api.github.com/users/air-upc/gists{/gist_id}","starred_url":"https://api.github.com/users/air-upc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/air-upc/subscriptions","organizations_url":"https://api.github.com/users/air-upc/orgs","repos_url":"https://api.github.com/users/air-upc/repos","events_url":"https://api.github.com/users/air-upc/events{/privacy}","received_events_url":"https://api.github.com/users/air-upc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-25T03:22:22Z","updated_at":"2016-07-27T09:27:36Z","closed_at":null,"body":"When I use `synloop` (in celery.worker.loops) to consume msg, I found that no heartbeat check is enabled when socket timeout occurs during drain events:\r\n\r\n``` python\r\ntry:\r\n    perform_pending_operations()\r\n    connection.drain_events(timeout=2.0)\r\nexcept socket.timeout:\r\n    pass  # here no heartbeat checked, just pass\r\n```\r\n\r\nbut in method `consume` of `ConsumerMixin` of `kombu.mixin`, we have\r\n\r\n``` python\r\ntry:\r\n    conn.drain_events(timeout=safety_interval)\r\nexcept socket.timeout:\r\n    conn.heartbeat_check()  # here checks the heartbeat when socket timeout\r\n```\r\n\r\nSo heartbeat check disabled by default in `celery.worker.loops:synloop` compared with `kombu.mixin:ConsumerMixin`, but I think it's better to check the heartbeat when socket timeout occurs. Is there something hinders us to check the connection heartbeat?\r\n\r\nAlso in `celery.worker.consumer.consumer:Consumer`,  the code will set heartbeat 0 when event IO hub not used:\r\n\r\n``` python\r\nif self.hub:\r\n    self.amqheartbeat = amqheartbeat\r\n    if self.amqheartbeat is None:\r\n        self.amqheartbeat = self.app.conf.broker_heartbeat\r\nelse:\r\n    self.amqheartbeat = 0  # in connection's heartbeat_tick method of amqp, just return\r\n```\r\n\r\nand in method `heartbeat_tick` of `py-amqp.amqp.connection:Connection`, we have:\r\n\r\n``` python\r\nif not self.heartbeat:\r\n    return\r\n```\r\n\r\nAs amqheartbeat == 0, no real heartbeat check is executed. Shall we make heartbeat check possible in celery synloop when socket timeout occurs?"},"comment":{"url":"https://api.github.com/repos/celery/celery/issues/comments/235534597","html_url":"https://github.com/celery/celery/issues/3338#issuecomment-235534597","issue_url":"https://api.github.com/repos/celery/celery/issues/3338","id":235534597,"user":{"login":"air-upc","id":14231765,"avatar_url":"https://avatars.githubusercontent.com/u/14231765?v=3","gravatar_id":"","url":"https://api.github.com/users/air-upc","html_url":"https://github.com/air-upc","followers_url":"https://api.github.com/users/air-upc/followers","following_url":"https://api.github.com/users/air-upc/following{/other_user}","gists_url":"https://api.github.com/users/air-upc/gists{/gist_id}","starred_url":"https://api.github.com/users/air-upc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/air-upc/subscriptions","organizations_url":"https://api.github.com/users/air-upc/orgs","repos_url":"https://api.github.com/users/air-upc/repos","events_url":"https://api.github.com/users/air-upc/events{/privacy}","received_events_url":"https://api.github.com/users/air-upc/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T09:27:36Z","updated_at":"2016-07-27T09:27:36Z","body":"For security and convenience, we disabled `event loop` and use `gevent` as our `taskpool` on platform `CentOS`. If concerns over this issue are much easier to deal with, can we add several lines of code to realise the heartbeat?"}}
{"actor":{"display_login":"air-upc"}}