{"action":"created","comment":{"url":"https://api.github.com/repos/square/p2/pulls/comments/57786650","id":57786650,"diff_hunk":"@@ -521,35 +521,75 @@ func (s consulStore) Lock(id roll_fields.ID, session string) (bool, error) {\n }\n \n func (s consulStore) Watch(quit <-chan struct{}) (<-chan []roll_fields.Update, <-chan error) {\n-\toutCh := make(chan []roll_fields.Update)\n-\terrCh := make(chan error)\n \tinCh := make(chan api.KVPairs)\n \n+\toutCh, errCh := publishLatestRolls(inCh, quit)\n \tgo consulutil.WatchPrefix(rollTree+\"/\", s.kv, inCh, quit, errCh)\n \n+\treturn outCh, errCh\n+}\n+\n+func publishLatestRolls(inCh <-chan api.KVPairs, quit <-chan struct{}) (<-chan []roll_fields.Update, chan error) {\n+\toutCh := make(chan []roll_fields.Update)\n+\terrCh := make(chan error)\n+\n \tgo func() {\n \t\tdefer close(outCh)\n \t\tdefer close(errCh)\n \n-\t\tfor listed := range inCh {\n+\t\tlisted, ok := <-inCh\n+\t\tif !ok {\n+\t\t\t// the channel was closed\n+\t\t\treturn\n+\t\t}\n+\n+\t\tneedToWrite := true\n+\n+\t\tfor {\n+\t\t\tif !needToWrite {\n+\t\t\t\tselect {\n+\t\t\t\tcase listed, ok = <-inCh:\n+\t\t\t\t\tif !ok {\n+\t\t\t\t\t\t// channel closed\n+\t\t\t\t\t\treturn\n+\t\t\t\t\t}\n+\t\t\t\tcase <-quit:\n+\t\t\t\t\treturn\n+\t\t\t\t}\n+\t\t\t}\n+\n \t\t\tout := make([]roll_fields.Update, 0, len(listed))\n \t\t\tfor _, kvp := range listed {\n \t\t\t\tvar next roll_fields.Update\n \t\t\t\tif err := json.Unmarshal(kvp.Value, &next); err != nil {\n \t\t\t\t\tselect {\n \t\t\t\t\tcase errCh <- err:\n+\t\t\t\t\t\t//abandon the value we were writing, it's probably corrupt\n+\t\t\t\t\t\tneedToWrite = false\n \t\t\t\t\tcase <-quit:\n \t\t\t\t\t\t// stop processing this kvp list; inCh should be closed\n \t\t\t\t\t\t// in a moment\n-\t\t\t\t\t\tbreak\n+\t\t\t\t\t\treturn\n \t\t\t\t\t}\n \t\t\t\t} else {\n \t\t\t\t\tout = append(out, next)\n \t\t\t\t}\n \t\t\t}\n-\t\t\tselect {\n-\t\t\tcase outCh <- out:\n-\t\t\tcase <-quit:\n+\n+\t\t\tif needToWrite {\n+\t\t\t\tselect {\n+\t\t\t\tcase outCh <- out:\n+\t\t\t\tcase listed, ok = <-inCh:\n+\t\t\t\t\tif !ok {\n+\t\t\t\t\t\t// channel closed\n+\t\t\t\t\t\treturn\n+\t\t\t\t\t}\n+\t\t\t\t\t// We got a new value before we write the old one,\n+\t\t\t\t\t// drop the old one\n+\t\t\t\t\tneedToWrite = true","path":"pkg/kp/rollstore/consul_store.go","position":76,"original_position":76,"commit_id":"c9b2eabab1c6c337333b016907f6e6c81dff9600","original_commit_id":"c9b2eabab1c6c337333b016907f6e6c81dff9600","user":{"login":"mpuncel","id":1444855,"avatar_url":"https://avatars.githubusercontent.com/u/1444855?v=3","gravatar_id":"","url":"https://api.github.com/users/mpuncel","html_url":"https://github.com/mpuncel","followers_url":"https://api.github.com/users/mpuncel/followers","following_url":"https://api.github.com/users/mpuncel/following{/other_user}","gists_url":"https://api.github.com/users/mpuncel/gists{/gist_id}","starred_url":"https://api.github.com/users/mpuncel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpuncel/subscriptions","organizations_url":"https://api.github.com/users/mpuncel/orgs","repos_url":"https://api.github.com/users/mpuncel/repos","events_url":"https://api.github.com/users/mpuncel/events{/privacy}","received_events_url":"https://api.github.com/users/mpuncel/received_events","type":"User","site_admin":false},"body":"yeah, but honestly I like it for clarity. Although i'm realizing i missed setting it to `false` in the case above","created_at":"2016-03-29T19:38:43Z","updated_at":"2016-03-29T19:38:43Z","html_url":"https://github.com/square/p2/pull/434#discussion_r57786650","pull_request_url":"https://api.github.com/repos/square/p2/pulls/434","_links":{"self":{"href":"https://api.github.com/repos/square/p2/pulls/comments/57786650"},"html":{"href":"https://github.com/square/p2/pull/434#discussion_r57786650"},"pull_request":{"href":"https://api.github.com/repos/square/p2/pulls/434"}}},"pull_request":{"url":"https://api.github.com/repos/square/p2/pulls/434","id":64198333,"html_url":"https://github.com/square/p2/pull/434","diff_url":"https://github.com/square/p2/pull/434.diff","patch_url":"https://github.com/square/p2/pull/434.patch","issue_url":"https://api.github.com/repos/square/p2/issues/434","number":434,"state":"open","locked":false,"title":"Only write the latest RC list to consumer of rcstore.WatchNew","user":{"login":"mpuncel","id":1444855,"avatar_url":"https://avatars.githubusercontent.com/u/1444855?v=3","gravatar_id":"","url":"https://api.github.com/users/mpuncel","html_url":"https://github.com/mpuncel","followers_url":"https://api.github.com/users/mpuncel/followers","following_url":"https://api.github.com/users/mpuncel/following{/other_user}","gists_url":"https://api.github.com/users/mpuncel/gists{/gist_id}","starred_url":"https://api.github.com/users/mpuncel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpuncel/subscriptions","organizations_url":"https://api.github.com/users/mpuncel/orgs","repos_url":"https://api.github.com/users/mpuncel/repos","events_url":"https://api.github.com/users/mpuncel/events{/privacy}","received_events_url":"https://api.github.com/users/mpuncel/received_events","type":"User","site_admin":false},"body":"Previously, if the consumer of the RC watch was very slow, we might\r\nreceive new updates from consul while we're still blocking on writing\r\nthe previous update. Now, if we receive a new update while still\r\nattempting to write the old one, we just move on to the most recent\r\nupdate.","created_at":"2016-03-25T19:31:41Z","updated_at":"2016-03-29T19:38:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab46e22adbd83c431aa0f934cff3efb961e07e59","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/square/p2/pulls/434/commits","review_comments_url":"https://api.github.com/repos/square/p2/pulls/434/comments","review_comment_url":"https://api.github.com/repos/square/p2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/square/p2/issues/434/comments","statuses_url":"https://api.github.com/repos/square/p2/statuses/c9b2eabab1c6c337333b016907f6e6c81dff9600","head":{"label":"mpuncel:mpuncel/rcstore-watch-fix","ref":"mpuncel/rcstore-watch-fix","sha":"c9b2eabab1c6c337333b016907f6e6c81dff9600","user":{"login":"mpuncel","id":1444855,"avatar_url":"https://avatars.githubusercontent.com/u/1444855?v=3","gravatar_id":"","url":"https://api.github.com/users/mpuncel","html_url":"https://github.com/mpuncel","followers_url":"https://api.github.com/users/mpuncel/followers","following_url":"https://api.github.com/users/mpuncel/following{/other_user}","gists_url":"https://api.github.com/users/mpuncel/gists{/gist_id}","starred_url":"https://api.github.com/users/mpuncel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpuncel/subscriptions","organizations_url":"https://api.github.com/users/mpuncel/orgs","repos_url":"https://api.github.com/users/mpuncel/repos","events_url":"https://api.github.com/users/mpuncel/events{/privacy}","received_events_url":"https://api.github.com/users/mpuncel/received_events","type":"User","site_admin":false},"repo":{"id":25327874,"name":"p2","full_name":"mpuncel/p2","owner":{"login":"mpuncel","id":1444855,"avatar_url":"https://avatars.githubusercontent.com/u/1444855?v=3","gravatar_id":"","url":"https://api.github.com/users/mpuncel","html_url":"https://github.com/mpuncel","followers_url":"https://api.github.com/users/mpuncel/followers","following_url":"https://api.github.com/users/mpuncel/following{/other_user}","gists_url":"https://api.github.com/users/mpuncel/gists{/gist_id}","starred_url":"https://api.github.com/users/mpuncel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpuncel/subscriptions","organizations_url":"https://api.github.com/users/mpuncel/orgs","repos_url":"https://api.github.com/users/mpuncel/repos","events_url":"https://api.github.com/users/mpuncel/events{/privacy}","received_events_url":"https://api.github.com/users/mpuncel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mpuncel/p2","description":"Platypus Platform: Tools for Scalable Deployment","fork":true,"url":"https://api.github.com/repos/mpuncel/p2","forks_url":"https://api.github.com/repos/mpuncel/p2/forks","keys_url":"https://api.github.com/repos/mpuncel/p2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mpuncel/p2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mpuncel/p2/teams","hooks_url":"https://api.github.com/repos/mpuncel/p2/hooks","issue_events_url":"https://api.github.com/repos/mpuncel/p2/issues/events{/number}","events_url":"https://api.github.com/repos/mpuncel/p2/events","assignees_url":"https://api.github.com/repos/mpuncel/p2/assignees{/user}","branches_url":"https://api.github.com/repos/mpuncel/p2/branches{/branch}","tags_url":"https://api.github.com/repos/mpuncel/p2/tags","blobs_url":"https://api.github.com/repos/mpuncel/p2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mpuncel/p2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mpuncel/p2/git/refs{/sha}","trees_url":"https://api.github.com/repos/mpuncel/p2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mpuncel/p2/statuses/{sha}","languages_url":"https://api.github.com/repos/mpuncel/p2/languages","stargazers_url":"https://api.github.com/repos/mpuncel/p2/stargazers","contributors_url":"https://api.github.com/repos/mpuncel/p2/contributors","subscribers_url":"https://api.github.com/repos/mpuncel/p2/subscribers","subscription_url":"https://api.github.com/repos/mpuncel/p2/subscription","commits_url":"https://api.github.com/repos/mpuncel/p2/commits{/sha}","git_commits_url":"https://api.github.com/repos/mpuncel/p2/git/commits{/sha}","comments_url":"https://api.github.com/repos/mpuncel/p2/comments{/number}","issue_comment_url":"https://api.github.com/repos/mpuncel/p2/issues/comments{/number}","contents_url":"https://api.github.com/repos/mpuncel/p2/contents/{+path}","compare_url":"https://api.github.com/repos/mpuncel/p2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mpuncel/p2/merges","archive_url":"https://api.github.com/repos/mpuncel/p2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mpuncel/p2/downloads","issues_url":"https://api.github.com/repos/mpuncel/p2/issues{/number}","pulls_url":"https://api.github.com/repos/mpuncel/p2/pulls{/number}","milestones_url":"https://api.github.com/repos/mpuncel/p2/milestones{/number}","notifications_url":"https://api.github.com/repos/mpuncel/p2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mpuncel/p2/labels{/name}","releases_url":"https://api.github.com/repos/mpuncel/p2/releases{/id}","deployments_url":"https://api.github.com/repos/mpuncel/p2/deployments","created_at":"2014-10-16T23:47:47Z","updated_at":"2015-05-05T17:43:40Z","pushed_at":"2016-03-29T19:36:17Z","git_url":"git://github.com/mpuncel/p2.git","ssh_url":"git@github.com:mpuncel/p2.git","clone_url":"https://github.com/mpuncel/p2.git","svn_url":"https://github.com/mpuncel/p2","homepage":"","size":33084,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"square:master","ref":"master","sha":"3f9a2a51029099bd9c26377e016e2280a72a6d76","user":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":25320424,"name":"p2","full_name":"square/p2","owner":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/square/p2","description":"Platypus Platform: Tools for Scalable Deployment","fork":false,"url":"https://api.github.com/repos/square/p2","forks_url":"https://api.github.com/repos/square/p2/forks","keys_url":"https://api.github.com/repos/square/p2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/p2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/p2/teams","hooks_url":"https://api.github.com/repos/square/p2/hooks","issue_events_url":"https://api.github.com/repos/square/p2/issues/events{/number}","events_url":"https://api.github.com/repos/square/p2/events","assignees_url":"https://api.github.com/repos/square/p2/assignees{/user}","branches_url":"https://api.github.com/repos/square/p2/branches{/branch}","tags_url":"https://api.github.com/repos/square/p2/tags","blobs_url":"https://api.github.com/repos/square/p2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/p2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/p2/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/p2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/p2/statuses/{sha}","languages_url":"https://api.github.com/repos/square/p2/languages","stargazers_url":"https://api.github.com/repos/square/p2/stargazers","contributors_url":"https://api.github.com/repos/square/p2/contributors","subscribers_url":"https://api.github.com/repos/square/p2/subscribers","subscription_url":"https://api.github.com/repos/square/p2/subscription","commits_url":"https://api.github.com/repos/square/p2/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/p2/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/p2/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/p2/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/p2/contents/{+path}","compare_url":"https://api.github.com/repos/square/p2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/p2/merges","archive_url":"https://api.github.com/repos/square/p2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/p2/downloads","issues_url":"https://api.github.com/repos/square/p2/issues{/number}","pulls_url":"https://api.github.com/repos/square/p2/pulls{/number}","milestones_url":"https://api.github.com/repos/square/p2/milestones{/number}","notifications_url":"https://api.github.com/repos/square/p2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/p2/labels{/name}","releases_url":"https://api.github.com/repos/square/p2/releases{/id}","deployments_url":"https://api.github.com/repos/square/p2/deployments","created_at":"2014-10-16T20:31:12Z","updated_at":"2016-03-12T13:29:23Z","pushed_at":"2016-03-29T19:36:18Z","git_url":"git://github.com/square/p2.git","ssh_url":"git@github.com:square/p2.git","clone_url":"https://github.com/square/p2.git","svn_url":"https://github.com/square/p2","homepage":"","size":33306,"stargazers_count":101,"watchers_count":101,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":5,"forks":18,"open_issues":5,"watchers":101,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/square/p2/pulls/434"},"html":{"href":"https://github.com/square/p2/pull/434"},"issue":{"href":"https://api.github.com/repos/square/p2/issues/434"},"comments":{"href":"https://api.github.com/repos/square/p2/issues/434/comments"},"review_comments":{"href":"https://api.github.com/repos/square/p2/pulls/434/comments"},"review_comment":{"href":"https://api.github.com/repos/square/p2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/square/p2/pulls/434/commits"},"statuses":{"href":"https://api.github.com/repos/square/p2/statuses/c9b2eabab1c6c337333b016907f6e6c81dff9600"}}}}