{"action":"created","issue":{"url":"https://api.github.com/repos/docker/swarm/issues/932","labels_url":"https://api.github.com/repos/docker/swarm/issues/932/labels{/name}","comments_url":"https://api.github.com/repos/docker/swarm/issues/932/comments","events_url":"https://api.github.com/repos/docker/swarm/issues/932/events","html_url":"https://github.com/docker/swarm/pull/932","id":87337225,"number":932,"title":"fix the panic when docker event emitted after engine removal (#836)","user":{"login":"mountkin","id":1496652,"avatar_url":"https://avatars.githubusercontent.com/u/1496652?v=3","gravatar_id":"","url":"https://api.github.com/users/mountkin","html_url":"https://github.com/mountkin","followers_url":"https://api.github.com/users/mountkin/followers","following_url":"https://api.github.com/users/mountkin/following{/other_user}","gists_url":"https://api.github.com/users/mountkin/gists{/gist_id}","starred_url":"https://api.github.com/users/mountkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountkin/subscriptions","organizations_url":"https://api.github.com/users/mountkin/orgs","repos_url":"https://api.github.com/users/mountkin/repos","events_url":"https://api.github.com/users/mountkin/events{/privacy}","received_events_url":"https://api.github.com/users/mountkin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/swarm/labels/status/0-needs-triage","name":"status/0-needs-triage","color":"EEEEEE"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-11T12:56:15Z","updated_at":"2015-06-11T13:27:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/docker/swarm/pulls/932","html_url":"https://github.com/docker/swarm/pull/932","diff_url":"https://github.com/docker/swarm/pull/932.diff","patch_url":"https://github.com/docker/swarm/pull/932.patch"},"body":"I think #836  should be reopen because #897 didn't really fix the panic.\r\nThe problem can still be reproduced by\r\n```\r\ndocker run -itd --name=test busybox sh\r\necho 127.0.0.1:2375 >/tmp/discovery.txt\r\n./swarm m -H :8888 file:///tmp/discovery.txt &\r\nsleep 5\r\necho >/tmp/discovery.txt\r\nsleep 60\r\ndocker rm -f test\r\n```\r\n \r\nThis panic is caused by the event monitor. When calling `StopAllMonitorEvents`, dockerclient just set `client.monitorEvents` to 0, but this doesn't prevent the json decoder from decoding new events.\r\nWhen new events are emitted after engine removal, the event will be passed to `engine.handler` as usual. But at this time the `e.client` is set to nil by `engine.Disconnect`, so the panic happens.\r\n\r\nThis PR leverages the `MonitorEvents` API of dockerclient, which accepts a `stopChan`. When the stopChan is readable, new events won't be returned to the calling procedure any more. \r\n\r\nSigned-off-by: Shijiang Wei <mountkin@gmail.com>"},"comment":{"url":"https://api.github.com/repos/docker/swarm/issues/comments/111135438","html_url":"https://github.com/docker/swarm/pull/932#issuecomment-111135438","issue_url":"https://api.github.com/repos/docker/swarm/issues/932","id":111135438,"user":{"login":"mountkin","id":1496652,"avatar_url":"https://avatars.githubusercontent.com/u/1496652?v=3","gravatar_id":"","url":"https://api.github.com/users/mountkin","html_url":"https://github.com/mountkin","followers_url":"https://api.github.com/users/mountkin/followers","following_url":"https://api.github.com/users/mountkin/following{/other_user}","gists_url":"https://api.github.com/users/mountkin/gists{/gist_id}","starred_url":"https://api.github.com/users/mountkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountkin/subscriptions","organizations_url":"https://api.github.com/users/mountkin/orgs","repos_url":"https://api.github.com/users/mountkin/repos","events_url":"https://api.github.com/users/mountkin/events{/privacy}","received_events_url":"https://api.github.com/users/mountkin/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T13:27:28Z","updated_at":"2015-06-11T13:27:28Z","body":"I think we can use the MonitorEvents API to implement a realtime engine health monitor. I'll give it a shot this weekend.\r\n\r\nI'll fix the broken test tomorrow."}}