{"action":"created","comment":{"url":"https://api.github.com/repos/docker/swarmkit/pulls/comments/73736954","id":73736954,"diff_hunk":"@@ -4,164 +4,115 @@ import (\n \t\"sync\"\n \t\"time\"\n \n-\t\"golang.org/x/net/context\"\n+\t\"github.com/Sirupsen/logrus\"\n+\n \t\"google.golang.org/grpc\"\n-\t\"google.golang.org/grpc/transport\"\n )\n \n-// picker always picks address of cluster leader.\n-type picker struct {\n-\tmu   sync.Mutex\n+// ConnSelector is struct for obtaining connection connected to cluster leader.\n+type ConnSelector struct {\n+\tmu      sync.Mutex\n+\tcluster RaftCluster\n+\topts    []grpc.DialOption\n+\n+\tcc   *grpc.ClientConn\n \taddr string\n-\traft AddrSelector\n-\tconn *grpc.Conn\n \n \tstop chan struct{}\n-\tdone chan struct{}\n }\n \n-func newPicker(raft AddrSelector, addr string) *picker {\n-\treturn &picker{\n-\t\traft: raft,\n-\t\taddr: addr,\n-\n-\t\tstop: make(chan struct{}),\n-\t\tdone: make(chan struct{}),\n+// NewConnSelector returns new ConnSelector with cluster and grpc.DialOpts which\n+// will be used for connection create.\n+func NewConnSelector(cluster RaftCluster, opts ...grpc.DialOption) *ConnSelector {\n+\tcs := &ConnSelector{\n+\t\tcluster: cluster,\n+\t\topts:    opts,\n+\t\tstop:    make(chan struct{}),\n \t}\n+\tgo cs.updateLoop()\n+\treturn cs\n }\n \n-// Init does initial processing for the Picker, e.g., initiate some connections.\n-func (p *picker) Init(cc *grpc.ClientConn) error {\n-\tconn, err := grpc.NewConn(cc)\n+// Conn returns *grpc.ClientConn which connected to cluster leader.\n+// It can return error if cluster wasn't ready at the moment of initial call.\n+func (c *ConnSelector) Conn() (*grpc.ClientConn, error) {\n+\tc.mu.Lock()\n+\tdefer c.mu.Unlock()\n+\tif c.cc != nil {\n+\t\treturn c.cc, nil\n+\t}\n+\taddr, err := c.cluster.LeaderAddr()\n \tif err != nil {\n-\t\treturn err\n+\t\treturn nil, err\n \t}\n-\tp.conn = conn\n-\treturn nil\n-}\n-\n-// Pick blocks until either a transport.ClientTransport is ready for the upcoming RPC\n-// or some error happens.\n-func (p *picker) Pick(ctx context.Context) (transport.ClientTransport, error) {\n-\tif err := p.updateConn(); err != nil {\n+\tcc, err := grpc.Dial(addr, c.opts...)\n+\tif err != nil {\n \t\treturn nil, err\n \t}\n-\treturn p.conn.Wait(ctx)\n+\tc.cc = cc\n+\tc.addr = addr\n+\treturn cc, nil\n }\n \n-// PickAddr picks a peer address for connecting. This will be called repeated for\n-// connecting/reconnecting.\n-func (p *picker) PickAddr() (string, error) {\n-\taddr, err := p.raft.LeaderAddr()\n+// Reset recreates underlying connection.\n+func (c *ConnSelector) Reset() error {\n+\tc.mu.Lock()\n+\tdefer c.mu.Unlock()\n+\tif c.cc != nil {\n+\t\tc.cc.Close()","path":"manager/raftpicker/raftpicker.go","position":91,"original_position":91,"commit_id":"128551699bdcb264a416f637299b9627d14e4edc","original_commit_id":"128551699bdcb264a416f637299b9627d14e4edc","user":{"login":"dongluochen","id":14985073,"avatar_url":"https://avatars.githubusercontent.com/u/14985073?v=3","gravatar_id":"","url":"https://api.github.com/users/dongluochen","html_url":"https://github.com/dongluochen","followers_url":"https://api.github.com/users/dongluochen/followers","following_url":"https://api.github.com/users/dongluochen/following{/other_user}","gists_url":"https://api.github.com/users/dongluochen/gists{/gist_id}","starred_url":"https://api.github.com/users/dongluochen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongluochen/subscriptions","organizations_url":"https://api.github.com/users/dongluochen/orgs","repos_url":"https://api.github.com/users/dongluochen/repos","events_url":"https://api.github.com/users/dongluochen/events{/privacy}","received_events_url":"https://api.github.com/users/dongluochen/received_events","type":"User","site_admin":false},"body":"Is double `Close()` allowed or not? I think there may be paths leading to double close. If it's a problem, it may make sense to set `c.cc = nil` right after `c.cc.Close()`. ","created_at":"2016-08-05T18:17:07Z","updated_at":"2016-08-05T18:17:07Z","html_url":"https://github.com/docker/swarmkit/pull/1313#discussion_r73736954","pull_request_url":"https://api.github.com/repos/docker/swarmkit/pulls/1313","_links":{"self":{"href":"https://api.github.com/repos/docker/swarmkit/pulls/comments/73736954"},"html":{"href":"https://github.com/docker/swarmkit/pull/1313#discussion_r73736954"},"pull_request":{"href":"https://api.github.com/repos/docker/swarmkit/pulls/1313"}}},"pull_request":{"url":"https://api.github.com/repos/docker/swarmkit/pulls/1313","id":80119191,"html_url":"https://github.com/docker/swarmkit/pull/1313","diff_url":"https://github.com/docker/swarmkit/pull/1313.diff","patch_url":"https://github.com/docker/swarmkit/pull/1313.patch","issue_url":"https://api.github.com/repos/docker/swarmkit/issues/1313","number":1313,"state":"open","locked":false,"title":"raftpicker: do not use picker","user":{"login":"LK4D4","id":101445,"avatar_url":"https://avatars.githubusercontent.com/u/101445?v=3","gravatar_id":"","url":"https://api.github.com/users/LK4D4","html_url":"https://github.com/LK4D4","followers_url":"https://api.github.com/users/LK4D4/followers","following_url":"https://api.github.com/users/LK4D4/following{/other_user}","gists_url":"https://api.github.com/users/LK4D4/gists{/gist_id}","starred_url":"https://api.github.com/users/LK4D4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LK4D4/subscriptions","organizations_url":"https://api.github.com/users/LK4D4/orgs","repos_url":"https://api.github.com/users/LK4D4/repos","events_url":"https://api.github.com/users/LK4D4/events{/privacy}","received_events_url":"https://api.github.com/users/LK4D4/received_events","type":"User","site_admin":false},"body":"Just recreate connection on leader change.\r\n\r\nping @aaronlehmann ","created_at":"2016-08-04T17:38:30Z","updated_at":"2016-08-05T18:17:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69b126767784aa3fbbb5c6c19ef9cec817ce9ee2","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/docker/swarmkit/milestones/6","html_url":"https://github.com/docker/swarmkit/milestones/1.12.1","labels_url":"https://api.github.com/repos/docker/swarmkit/milestones/6/labels","id":1906142,"number":6,"title":"1.12.1","description":"","creator":{"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},"open_issues":5,"closed_issues":21,"state":"open","created_at":"2016-07-27T00:34:17Z","updated_at":"2016-08-05T17:43:11Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/docker/swarmkit/pulls/1313/commits","review_comments_url":"https://api.github.com/repos/docker/swarmkit/pulls/1313/comments","review_comment_url":"https://api.github.com/repos/docker/swarmkit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/swarmkit/issues/1313/comments","statuses_url":"https://api.github.com/repos/docker/swarmkit/statuses/128551699bdcb264a416f637299b9627d14e4edc","head":{"label":"LK4D4:no_raft_picker","ref":"no_raft_picker","sha":"128551699bdcb264a416f637299b9627d14e4edc","user":{"login":"LK4D4","id":101445,"avatar_url":"https://avatars.githubusercontent.com/u/101445?v=3","gravatar_id":"","url":"https://api.github.com/users/LK4D4","html_url":"https://github.com/LK4D4","followers_url":"https://api.github.com/users/LK4D4/followers","following_url":"https://api.github.com/users/LK4D4/following{/other_user}","gists_url":"https://api.github.com/users/LK4D4/gists{/gist_id}","starred_url":"https://api.github.com/users/LK4D4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LK4D4/subscriptions","organizations_url":"https://api.github.com/users/LK4D4/orgs","repos_url":"https://api.github.com/users/LK4D4/repos","events_url":"https://api.github.com/users/LK4D4/events{/privacy}","received_events_url":"https://api.github.com/users/LK4D4/received_events","type":"User","site_admin":false},"repo":{"id":60712803,"name":"swarmkit","full_name":"LK4D4/swarmkit","owner":{"login":"LK4D4","id":101445,"avatar_url":"https://avatars.githubusercontent.com/u/101445?v=3","gravatar_id":"","url":"https://api.github.com/users/LK4D4","html_url":"https://github.com/LK4D4","followers_url":"https://api.github.com/users/LK4D4/followers","following_url":"https://api.github.com/users/LK4D4/following{/other_user}","gists_url":"https://api.github.com/users/LK4D4/gists{/gist_id}","starred_url":"https://api.github.com/users/LK4D4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LK4D4/subscriptions","organizations_url":"https://api.github.com/users/LK4D4/orgs","repos_url":"https://api.github.com/users/LK4D4/repos","events_url":"https://api.github.com/users/LK4D4/events{/privacy}","received_events_url":"https://api.github.com/users/LK4D4/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/LK4D4/swarmkit","description":"A toolkit for orchestrating distributed systems at any scale. It includes primitives for node discovery, raft-based consensus, task scheduling and more.","fork":true,"url":"https://api.github.com/repos/LK4D4/swarmkit","forks_url":"https://api.github.com/repos/LK4D4/swarmkit/forks","keys_url":"https://api.github.com/repos/LK4D4/swarmkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/LK4D4/swarmkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/LK4D4/swarmkit/teams","hooks_url":"https://api.github.com/repos/LK4D4/swarmkit/hooks","issue_events_url":"https://api.github.com/repos/LK4D4/swarmkit/issues/events{/number}","events_url":"https://api.github.com/repos/LK4D4/swarmkit/events","assignees_url":"https://api.github.com/repos/LK4D4/swarmkit/assignees{/user}","branches_url":"https://api.github.com/repos/LK4D4/swarmkit/branches{/branch}","tags_url":"https://api.github.com/repos/LK4D4/swarmkit/tags","blobs_url":"https://api.github.com/repos/LK4D4/swarmkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/LK4D4/swarmkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/LK4D4/swarmkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/LK4D4/swarmkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/LK4D4/swarmkit/statuses/{sha}","languages_url":"https://api.github.com/repos/LK4D4/swarmkit/languages","stargazers_url":"https://api.github.com/repos/LK4D4/swarmkit/stargazers","contributors_url":"https://api.github.com/repos/LK4D4/swarmkit/contributors","subscribers_url":"https://api.github.com/repos/LK4D4/swarmkit/subscribers","subscription_url":"https://api.github.com/repos/LK4D4/swarmkit/subscription","commits_url":"https://api.github.com/repos/LK4D4/swarmkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/LK4D4/swarmkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/LK4D4/swarmkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/LK4D4/swarmkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/LK4D4/swarmkit/contents/{+path}","compare_url":"https://api.github.com/repos/LK4D4/swarmkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/LK4D4/swarmkit/merges","archive_url":"https://api.github.com/repos/LK4D4/swarmkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/LK4D4/swarmkit/downloads","issues_url":"https://api.github.com/repos/LK4D4/swarmkit/issues{/number}","pulls_url":"https://api.github.com/repos/LK4D4/swarmkit/pulls{/number}","milestones_url":"https://api.github.com/repos/LK4D4/swarmkit/milestones{/number}","notifications_url":"https://api.github.com/repos/LK4D4/swarmkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/LK4D4/swarmkit/labels{/name}","releases_url":"https://api.github.com/repos/LK4D4/swarmkit/releases{/id}","deployments_url":"https://api.github.com/repos/LK4D4/swarmkit/deployments","created_at":"2016-06-08T16:28:10Z","updated_at":"2016-06-08T16:28:12Z","pushed_at":"2016-08-05T18:14:19Z","git_url":"git://github.com/LK4D4/swarmkit.git","ssh_url":"git@github.com:LK4D4/swarmkit.git","clone_url":"https://github.com/LK4D4/swarmkit.git","svn_url":"https://github.com/LK4D4/swarmkit","homepage":"","size":8824,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"e021d1412c851ed7f63713008f4562c689093677","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":51556828,"name":"swarmkit","full_name":"docker/swarmkit","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/swarmkit","description":"A toolkit for orchestrating distributed systems at any scale. It includes primitives for node discovery, raft-based consensus, task scheduling and more.","fork":false,"url":"https://api.github.com/repos/docker/swarmkit","forks_url":"https://api.github.com/repos/docker/swarmkit/forks","keys_url":"https://api.github.com/repos/docker/swarmkit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/swarmkit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/swarmkit/teams","hooks_url":"https://api.github.com/repos/docker/swarmkit/hooks","issue_events_url":"https://api.github.com/repos/docker/swarmkit/issues/events{/number}","events_url":"https://api.github.com/repos/docker/swarmkit/events","assignees_url":"https://api.github.com/repos/docker/swarmkit/assignees{/user}","branches_url":"https://api.github.com/repos/docker/swarmkit/branches{/branch}","tags_url":"https://api.github.com/repos/docker/swarmkit/tags","blobs_url":"https://api.github.com/repos/docker/swarmkit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/swarmkit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/swarmkit/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/swarmkit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/swarmkit/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/swarmkit/languages","stargazers_url":"https://api.github.com/repos/docker/swarmkit/stargazers","contributors_url":"https://api.github.com/repos/docker/swarmkit/contributors","subscribers_url":"https://api.github.com/repos/docker/swarmkit/subscribers","subscription_url":"https://api.github.com/repos/docker/swarmkit/subscription","commits_url":"https://api.github.com/repos/docker/swarmkit/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/swarmkit/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/swarmkit/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/swarmkit/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/swarmkit/contents/{+path}","compare_url":"https://api.github.com/repos/docker/swarmkit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/swarmkit/merges","archive_url":"https://api.github.com/repos/docker/swarmkit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/swarmkit/downloads","issues_url":"https://api.github.com/repos/docker/swarmkit/issues{/number}","pulls_url":"https://api.github.com/repos/docker/swarmkit/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/swarmkit/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/swarmkit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/swarmkit/labels{/name}","releases_url":"https://api.github.com/repos/docker/swarmkit/releases{/id}","deployments_url":"https://api.github.com/repos/docker/swarmkit/deployments","created_at":"2016-02-12T00:02:15Z","updated_at":"2016-08-05T06:40:33Z","pushed_at":"2016-08-05T18:14:20Z","git_url":"git://github.com/docker/swarmkit.git","ssh_url":"git@github.com:docker/swarmkit.git","clone_url":"https://github.com/docker/swarmkit.git","svn_url":"https://github.com/docker/swarmkit","homepage":"","size":19619,"stargazers_count":861,"watchers_count":861,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":149,"mirror_url":null,"open_issues_count":158,"forks":149,"open_issues":158,"watchers":861,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/swarmkit/pulls/1313"},"html":{"href":"https://github.com/docker/swarmkit/pull/1313"},"issue":{"href":"https://api.github.com/repos/docker/swarmkit/issues/1313"},"comments":{"href":"https://api.github.com/repos/docker/swarmkit/issues/1313/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/swarmkit/pulls/1313/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/swarmkit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/swarmkit/pulls/1313/commits"},"statuses":{"href":"https://api.github.com/repos/docker/swarmkit/statuses/128551699bdcb264a416f637299b9627d14e4edc"}}}}
{"actor":{"display_login":"dongluochen"}}