{"action":"created","comment":{"url":"https://api.github.com/repos/docker/swarm/pulls/comments/36024337","id":36024337,"diff_hunk":"@@ -128,34 +130,56 @@ func setupReplication(c *cli.Context, cluster cluster.Cluster, server *api.Serve\n \tprimary := api.NewPrimary(cluster, tlsConfig, &statusHandler{cluster, candidate, follower}, c.Bool(\"cors\"))\n \treplica := api.NewReplica(primary, tlsConfig)\n \n-\tgo func() {\n-\t\tcandidate.RunForElection()\n-\t\telectedCh := candidate.ElectedCh()\n-\t\tfor isElected := range electedCh {\n+\tgo run(candidate, server, primary, replica)\n+\tgo follow(follower, replica, addr)\n+\n+\tserver.SetHandler(primary)\n+}\n+\n+func run(candidate *leadership.Candidate, server *api.Server, primary *mux.Router, replica *api.Replica) {\n+\telectedCh, errCh := candidate.RunForElection()\n+\tfor {\n+\t\tselect {\n+\t\tcase isElected := <-electedCh:\n \t\t\tif isElected {\n-\t\t\t\tlog.Info(\"Cluster leadership acquired\")\n+\t\t\t\tlog.Info(\"Leader Election: Cluster leadership acquired\")\n \t\t\t\tserver.SetHandler(primary)\n \t\t\t} else {\n-\t\t\t\tlog.Info(\"Cluster leadership lost\")\n+\t\t\t\tlog.Info(\"Leader Election: Cluster leadership lost\")\n \t\t\t\tserver.SetHandler(replica)\n \t\t\t}\n+\n+\t\tcase err := <-errCh:\n+\t\t\tlog.Error(err)\n+\t\t\ttime.Sleep(defaultRecoverTime)\n+\t\t\tgo run(candidate, server, primary, replica)","path":"cli/manage.go","position":45,"original_position":45,"commit_id":"adcc7bf6c69a5187432814c1a33a336f287e5e6e","original_commit_id":"adcc7bf6c69a5187432814c1a33a336f287e5e6e","user":{"login":"aluzzardi","id":179503,"avatar_url":"https://avatars.githubusercontent.com/u/179503?v=3","gravatar_id":"","url":"https://api.github.com/users/aluzzardi","html_url":"https://github.com/aluzzardi","followers_url":"https://api.github.com/users/aluzzardi/followers","following_url":"https://api.github.com/users/aluzzardi/following{/other_user}","gists_url":"https://api.github.com/users/aluzzardi/gists{/gist_id}","starred_url":"https://api.github.com/users/aluzzardi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aluzzardi/subscriptions","organizations_url":"https://api.github.com/users/aluzzardi/orgs","repos_url":"https://api.github.com/users/aluzzardi/repos","events_url":"https://api.github.com/users/aluzzardi/events{/privacy}","received_events_url":"https://api.github.com/users/aluzzardi/received_events","type":"User","site_admin":false},"body":"This is a little weird - when you call `run()` it will block but then when it returns it will continue running as a goroutine in the background.\r\n\r\nHow about just returning here? And in `setupReplication`:\r\n```go\r\ngo func() {\r\n  for {\r\n    run(...)\r\n    time.Sleep(...)\r\n   }\r\n}\r\n```","created_at":"2015-07-31T23:03:12Z","updated_at":"2015-07-31T23:03:12Z","html_url":"https://github.com/docker/swarm/pull/1078#discussion_r36024337","pull_request_url":"https://api.github.com/repos/docker/swarm/pulls/1078","_links":{"self":{"href":"https://api.github.com/repos/docker/swarm/pulls/comments/36024337"},"html":{"href":"https://github.com/docker/swarm/pull/1078#discussion_r36024337"},"pull_request":{"href":"https://api.github.com/repos/docker/swarm/pulls/1078"}}},"pull_request":{"url":"https://api.github.com/repos/docker/swarm/pulls/1078","id":40398206,"html_url":"https://github.com/docker/swarm/pull/1078","diff_url":"https://github.com/docker/swarm/pull/1078.diff","patch_url":"https://github.com/docker/swarm/pull/1078.patch","issue_url":"https://api.github.com/repos/docker/swarm/issues/1078","number":1078,"state":"open","locked":false,"title":"Leadership: Fault tolerant Leader Election mechanism","user":{"login":"abronan","id":1655859,"avatar_url":"https://avatars.githubusercontent.com/u/1655859?v=3","gravatar_id":"","url":"https://api.github.com/users/abronan","html_url":"https://github.com/abronan","followers_url":"https://api.github.com/users/abronan/followers","following_url":"https://api.github.com/users/abronan/following{/other_user}","gists_url":"https://api.github.com/users/abronan/gists{/gist_id}","starred_url":"https://api.github.com/users/abronan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abronan/subscriptions","organizations_url":"https://api.github.com/users/abronan/orgs","repos_url":"https://api.github.com/users/abronan/repos","events_url":"https://api.github.com/users/abronan/events{/privacy}","received_events_url":"https://api.github.com/users/abronan/received_events","type":"User","site_admin":false},"body":"Makes the leader Election process resilient to failures of the backend storage (on Consul and etcd, zookeeper already allowed that naturally by keeping the leader information) using an error channel.\r\n\r\nFixes #982 #983 #1025 \r\n\r\nSigned-off-by: Alexandre Beslic <abronan@docker.com>","created_at":"2015-07-20T21:16:44Z","updated_at":"2015-07-31T23:03:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4bdea9bb405dd170ebdd5f7f13e9cd05df509af1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/swarm/pulls/1078/commits","review_comments_url":"https://api.github.com/repos/docker/swarm/pulls/1078/comments","review_comment_url":"https://api.github.com/repos/docker/swarm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/swarm/issues/1078/comments","statuses_url":"https://api.github.com/repos/docker/swarm/statuses/adcc7bf6c69a5187432814c1a33a336f287e5e6e","head":{"label":"abronan:leader_election_retry","ref":"leader_election_retry","sha":"adcc7bf6c69a5187432814c1a33a336f287e5e6e","user":{"login":"abronan","id":1655859,"avatar_url":"https://avatars.githubusercontent.com/u/1655859?v=3","gravatar_id":"","url":"https://api.github.com/users/abronan","html_url":"https://github.com/abronan","followers_url":"https://api.github.com/users/abronan/followers","following_url":"https://api.github.com/users/abronan/following{/other_user}","gists_url":"https://api.github.com/users/abronan/gists{/gist_id}","starred_url":"https://api.github.com/users/abronan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abronan/subscriptions","organizations_url":"https://api.github.com/users/abronan/orgs","repos_url":"https://api.github.com/users/abronan/repos","events_url":"https://api.github.com/users/abronan/events{/privacy}","received_events_url":"https://api.github.com/users/abronan/received_events","type":"User","site_admin":false},"repo":{"id":32493940,"name":"swarm","full_name":"abronan/swarm","owner":{"login":"abronan","id":1655859,"avatar_url":"https://avatars.githubusercontent.com/u/1655859?v=3","gravatar_id":"","url":"https://api.github.com/users/abronan","html_url":"https://github.com/abronan","followers_url":"https://api.github.com/users/abronan/followers","following_url":"https://api.github.com/users/abronan/following{/other_user}","gists_url":"https://api.github.com/users/abronan/gists{/gist_id}","starred_url":"https://api.github.com/users/abronan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abronan/subscriptions","organizations_url":"https://api.github.com/users/abronan/orgs","repos_url":"https://api.github.com/users/abronan/repos","events_url":"https://api.github.com/users/abronan/events{/privacy}","received_events_url":"https://api.github.com/users/abronan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abronan/swarm","description":"Swarm: a Docker-native clustering system","fork":true,"url":"https://api.github.com/repos/abronan/swarm","forks_url":"https://api.github.com/repos/abronan/swarm/forks","keys_url":"https://api.github.com/repos/abronan/swarm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abronan/swarm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abronan/swarm/teams","hooks_url":"https://api.github.com/repos/abronan/swarm/hooks","issue_events_url":"https://api.github.com/repos/abronan/swarm/issues/events{/number}","events_url":"https://api.github.com/repos/abronan/swarm/events","assignees_url":"https://api.github.com/repos/abronan/swarm/assignees{/user}","branches_url":"https://api.github.com/repos/abronan/swarm/branches{/branch}","tags_url":"https://api.github.com/repos/abronan/swarm/tags","blobs_url":"https://api.github.com/repos/abronan/swarm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abronan/swarm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abronan/swarm/git/refs{/sha}","trees_url":"https://api.github.com/repos/abronan/swarm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abronan/swarm/statuses/{sha}","languages_url":"https://api.github.com/repos/abronan/swarm/languages","stargazers_url":"https://api.github.com/repos/abronan/swarm/stargazers","contributors_url":"https://api.github.com/repos/abronan/swarm/contributors","subscribers_url":"https://api.github.com/repos/abronan/swarm/subscribers","subscription_url":"https://api.github.com/repos/abronan/swarm/subscription","commits_url":"https://api.github.com/repos/abronan/swarm/commits{/sha}","git_commits_url":"https://api.github.com/repos/abronan/swarm/git/commits{/sha}","comments_url":"https://api.github.com/repos/abronan/swarm/comments{/number}","issue_comment_url":"https://api.github.com/repos/abronan/swarm/issues/comments{/number}","contents_url":"https://api.github.com/repos/abronan/swarm/contents/{+path}","compare_url":"https://api.github.com/repos/abronan/swarm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abronan/swarm/merges","archive_url":"https://api.github.com/repos/abronan/swarm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abronan/swarm/downloads","issues_url":"https://api.github.com/repos/abronan/swarm/issues{/number}","pulls_url":"https://api.github.com/repos/abronan/swarm/pulls{/number}","milestones_url":"https://api.github.com/repos/abronan/swarm/milestones{/number}","notifications_url":"https://api.github.com/repos/abronan/swarm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abronan/swarm/labels{/name}","releases_url":"https://api.github.com/repos/abronan/swarm/releases{/id}","created_at":"2015-03-19T01:27:04Z","updated_at":"2015-04-14T10:52:26Z","pushed_at":"2015-07-30T19:14:12Z","git_url":"git://github.com/abronan/swarm.git","ssh_url":"git@github.com:abronan/swarm.git","clone_url":"https://github.com/abronan/swarm.git","svn_url":"https://github.com/abronan/swarm","homepage":"","size":6209,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"5f207e6fe98f60b988924c29d38df4156a8972e1","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":19360616,"name":"swarm","full_name":"docker/swarm","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/swarm","description":"Swarm: a Docker-native clustering system","fork":false,"url":"https://api.github.com/repos/docker/swarm","forks_url":"https://api.github.com/repos/docker/swarm/forks","keys_url":"https://api.github.com/repos/docker/swarm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/swarm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/swarm/teams","hooks_url":"https://api.github.com/repos/docker/swarm/hooks","issue_events_url":"https://api.github.com/repos/docker/swarm/issues/events{/number}","events_url":"https://api.github.com/repos/docker/swarm/events","assignees_url":"https://api.github.com/repos/docker/swarm/assignees{/user}","branches_url":"https://api.github.com/repos/docker/swarm/branches{/branch}","tags_url":"https://api.github.com/repos/docker/swarm/tags","blobs_url":"https://api.github.com/repos/docker/swarm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/swarm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/swarm/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/swarm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/swarm/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/swarm/languages","stargazers_url":"https://api.github.com/repos/docker/swarm/stargazers","contributors_url":"https://api.github.com/repos/docker/swarm/contributors","subscribers_url":"https://api.github.com/repos/docker/swarm/subscribers","subscription_url":"https://api.github.com/repos/docker/swarm/subscription","commits_url":"https://api.github.com/repos/docker/swarm/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/swarm/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/swarm/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/swarm/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/swarm/contents/{+path}","compare_url":"https://api.github.com/repos/docker/swarm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/swarm/merges","archive_url":"https://api.github.com/repos/docker/swarm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/swarm/downloads","issues_url":"https://api.github.com/repos/docker/swarm/issues{/number}","pulls_url":"https://api.github.com/repos/docker/swarm/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/swarm/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/swarm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/swarm/labels{/name}","releases_url":"https://api.github.com/repos/docker/swarm/releases{/id}","created_at":"2014-05-01T23:15:17Z","updated_at":"2015-07-31T20:16:02Z","pushed_at":"2015-07-31T21:15:53Z","git_url":"git://github.com/docker/swarm.git","ssh_url":"git@github.com:docker/swarm.git","clone_url":"https://github.com/docker/swarm.git","svn_url":"https://github.com/docker/swarm","homepage":"","size":12952,"stargazers_count":2938,"watchers_count":2938,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":391,"mirror_url":null,"open_issues_count":123,"forks":391,"open_issues":123,"watchers":2938,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/swarm/pulls/1078"},"html":{"href":"https://github.com/docker/swarm/pull/1078"},"issue":{"href":"https://api.github.com/repos/docker/swarm/issues/1078"},"comments":{"href":"https://api.github.com/repos/docker/swarm/issues/1078/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/swarm/pulls/1078/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/swarm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/swarm/pulls/1078/commits"},"statuses":{"href":"https://api.github.com/repos/docker/swarm/statuses/adcc7bf6c69a5187432814c1a33a336f287e5e6e"}}}}