{"action":"created","issue":{"url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/513","labels_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/513/labels{/name}","comments_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/513/comments","events_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/513/events","html_url":"https://github.com/OpenZWave/open-zwave/pull/513","id":67910260,"number":513,"title":"Fix for CPU-spinning on device disconnection","user":{"login":"stromnet","id":668449,"avatar_url":"https://avatars.githubusercontent.com/u/668449?v=3","gravatar_id":"","url":"https://api.github.com/users/stromnet","html_url":"https://github.com/stromnet","followers_url":"https://api.github.com/users/stromnet/followers","following_url":"https://api.github.com/users/stromnet/following{/other_user}","gists_url":"https://api.github.com/users/stromnet/gists{/gist_id}","starred_url":"https://api.github.com/users/stromnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stromnet/subscriptions","organizations_url":"https://api.github.com/users/stromnet/orgs","repos_url":"https://api.github.com/users/stromnet/repos","events_url":"https://api.github.com/users/stromnet/events{/privacy}","received_events_url":"https://api.github.com/users/stromnet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-12T12:41:38Z","updated_at":"2015-04-13T02:56:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/513","html_url":"https://github.com/OpenZWave/open-zwave/pull/513","diff_url":"https://github.com/OpenZWave/open-zwave/pull/513.diff","patch_url":"https://github.com/OpenZWave/open-zwave/pull/513.patch"},"body":"Hi,\r\nthis is an attempt to fix the issue with disconnected devices, which currently isn't handled very well.\r\n\r\nIf a serial port device was disconnected, we got stuck in read loop burning CPU cycles and having a unusable device.\r\n\r\nOn disconnect (at least on FreeBSD), select() will return 1 indicating\r\nFD ready to read. The subsequent read() would however return 0. This would would go on until the process was killed, yielding unusable device, and high CPU usage.\r\nWith this patch, we break out of the read loop and re-init the connection if this condition occurs.\r\n\r\n\r\nThis has been tested on FreeBSD 10.1 with an Aeon Labs 2 dongle. On this setup, disconnecting and then reconnecting the device works without any problems, and communication seems to be restored. I'm not sure if there are any higher-level issues with this though, there may be buffers which should be flushed on re-init or similar?\r\n\r\nTesting should be done on other supported platforms to verify that it works."},"comment":{"url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/comments/92178483","html_url":"https://github.com/OpenZWave/open-zwave/pull/513#issuecomment-92178483","issue_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/513","id":92178483,"user":{"login":"Fishwaldo","id":842308,"avatar_url":"https://avatars.githubusercontent.com/u/842308?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishwaldo","html_url":"https://github.com/Fishwaldo","followers_url":"https://api.github.com/users/Fishwaldo/followers","following_url":"https://api.github.com/users/Fishwaldo/following{/other_user}","gists_url":"https://api.github.com/users/Fishwaldo/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishwaldo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishwaldo/subscriptions","organizations_url":"https://api.github.com/users/Fishwaldo/orgs","repos_url":"https://api.github.com/users/Fishwaldo/repos","events_url":"https://api.github.com/users/Fishwaldo/events{/privacy}","received_events_url":"https://api.github.com/users/Fishwaldo/received_events","type":"User","site_admin":false},"created_at":"2015-04-13T02:56:27Z","updated_at":"2015-04-13T02:56:27Z","body":"Hi,\r\nThis issue has already been discussed in Issue 111. You patch only addresses a small part of it. We still need to propagate the disconnect up the stack (to the Driver and then to the Manager, and of course consider a notification to the Application).\r\n\r\nJust re-opening the Serial Port is not the complete fix here. We would probably need to also re-init the Controller. \r\n\r\nAlso, I think most times, the issue here is going to be more along the lines of the USB stick going unresponsive or falling out. At the moment, if the stick is not re-inserted, we will just spin, and instead of consuming CPU, we will start consuming memory and the message queues build up. :)\r\n\r\nI will ultimately merge this, but I think it needs more work to address the issue. Thanks for getting started on this.  "}}