{"action":"opened","issue":{"url":"https://api.github.com/repos/lazcad/homeassistant/issues/38","repository_url":"https://api.github.com/repos/lazcad/homeassistant","labels_url":"https://api.github.com/repos/lazcad/homeassistant/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/lazcad/homeassistant/issues/38/comments","events_url":"https://api.github.com/repos/lazcad/homeassistant/issues/38/events","html_url":"https://github.com/lazcad/homeassistant/issues/38","id":217959643,"number":38,"title":"Sync socket API usage breaks MainThread on long requests","user":{"login":"PaulAnnekov","id":1203892,"avatar_url":"https://avatars1.githubusercontent.com/u/1203892?v=3","gravatar_id":"","url":"https://api.github.com/users/PaulAnnekov","html_url":"https://github.com/PaulAnnekov","followers_url":"https://api.github.com/users/PaulAnnekov/followers","following_url":"https://api.github.com/users/PaulAnnekov/following{/other_user}","gists_url":"https://api.github.com/users/PaulAnnekov/gists{/gist_id}","starred_url":"https://api.github.com/users/PaulAnnekov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaulAnnekov/subscriptions","organizations_url":"https://api.github.com/users/PaulAnnekov/orgs","repos_url":"https://api.github.com/users/PaulAnnekov/repos","events_url":"https://api.github.com/users/PaulAnnekov/events{/privacy}","received_events_url":"https://api.github.com/users/PaulAnnekov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-03-29T18:02:37Z","updated_at":"2017-03-29T18:02:37Z","closed_at":null,"body":"Looks like this component is doing its work synchronous in the MainThread. That's unacceptable. Each socket request blocks main HA thread = blocks all the core. If your gateway or anybody between HA and a gateway (e.g. router) will respond too long (I think more than 1 sec), thread will be blocked for this time. E.g. my router likes to make socket timeouts (>10 secs) at least 1 time a day, thread is blocked for 10 seconds, it looks like this:\r\n\r\n```\r\n...\r\nhome_assistant_1  | 17-03-29 20:40:47 DEBUG (MainThread) [custom_components.xiaomi] >> b'{ \"cmd\":\"read\",\"sid\":\"128d001123ca9a\"}'\r\nhome_assistant_1  | 17-03-29 20:40:49 ERROR (Thread-7) [homeassistant.components.light.yeelight] Unable to update bulb status: Bulb closed the connection.\r\nhome_assistant_1  | 17-03-29 20:40:57 ERROR (MainThread) [custom_components.xiaomi] Cannot connect to Gateway\r\nhome_assistant_1  | 17-03-29 20:40:57 ERROR (MainThread) [custom_components.xiaomi] No data in response from hub None\r\nhome_assistant_1  | 17-03-29 20:40:57 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting\r\n...\r\n```\r\n\r\n[These calls](https://github.com/lazcad/homeassistant/blob/af4d2794bf1bc4ec1e50eef1c2febe2b4cd29f78/components/xiaomi.py#L318) should be rewritten with [asyncore](https://docs.python.org/2/library/asyncore.html) or it should use the same API as other components use (check [this](https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/device_tracker/__init__.py#L118) and everything below to understand how it should be implemented).\r\n"}}
{"actor":{"display_login":"PaulAnnekov"}}