{"action":"created","comment":{"url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/comments/230487634","pull_request_review_id":171245633,"id":230487634,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMDQ4NzYzNA==","diff_hunk":"@@ -0,0 +1,144 @@\n+package vkubelet\n+\n+import (\n+\t\"context\"\n+\t\"errors\"\n+\t\"sync\"\n+\t\"sync/atomic\"\n+)\n+\n+func NewCancellableMutex() *CancellableMutex {\n+\treturn &CancellableMutex{\n+\t\tch: make(chan struct{}, 1),\n+\t}\n+}\n+\n+// CancellableMutex is a mutex in which the Lock() action can be canncelled by\n+// cancelling a context.\n+// This must be initialized iby calling `NwwCancellableMutex()`\n+//\n+// You should expect this to be quite a bit slower than a normal sync.Mutex from\n+//n the stdlib.\n+type CancellableMutex struct {\n+\tch chan struct{}\n+}\n+\n+// Lock locks the mutex.\n+// If the passed in context is cancelled before the mutex can be acquired the\n+// lock request will be cancelled and an error will be returned.\n+//\n+// An error is only returned if the context was cancelled.\n+func (m *CancellableMutex) Lock(ctx context.Context) error {\n+\tif m.ch == nil {\n+\t\tpanic(\"cancellable mutex is not initialized\")\n+\t}\n+\n+\tselect {\n+\tcase <-ctx.Done():\n+\t\treturn ctx.Err()\n+\tcase m.ch <- struct{}{}:\n+\t}\n+\treturn nil\n+}\n+\n+// Unlock unlocks the mutex\n+// This will panic if the mutex is not locked.\n+func (m *CancellableMutex) Unlock() {\n+\tselect {\n+\tcase <-m.ch:\n+\tdefault:\n+\t\tpanic(\"unlock of unlocked mutex\")\n+\t}\n+}\n+\n+// ErrNoSuchLock is returned when the requested lock does not exist\n+var ErrNoSuchLock = errors.New(\"no such lock\")\n+\n+// NamedLock provides a locking mechanism based on the passed in reference name\n+type NamedLock struct {\n+\tmu    sync.Mutex","path":"vkubelet/sync.go","position":59,"original_position":59,"commit_id":"51725e1c29430d584dda2bec8f42296e90fbfb4b","original_commit_id":"51725e1c29430d584dda2bec8f42296e90fbfb4b","user":{"login":"robbiezhang","id":9003737,"node_id":"MDQ6VXNlcjkwMDM3Mzc=","avatar_url":"https://avatars1.githubusercontent.com/u/9003737?v=4","gravatar_id":"","url":"https://api.github.com/users/robbiezhang","html_url":"https://github.com/robbiezhang","followers_url":"https://api.github.com/users/robbiezhang/followers","following_url":"https://api.github.com/users/robbiezhang/following{/other_user}","gists_url":"https://api.github.com/users/robbiezhang/gists{/gist_id}","starred_url":"https://api.github.com/users/robbiezhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robbiezhang/subscriptions","organizations_url":"https://api.github.com/users/robbiezhang/orgs","repos_url":"https://api.github.com/users/robbiezhang/repos","events_url":"https://api.github.com/users/robbiezhang/events{/privacy}","received_events_url":"https://api.github.com/users/robbiezhang/received_events","type":"User","site_admin":false},"body":"use *sync.Mutex or derive from sync.Mutex","created_at":"2018-11-02T19:44:36Z","updated_at":"2018-11-02T19:44:37Z","html_url":"https://github.com/virtual-kubelet/virtual-kubelet/pull/393#discussion_r230487634","pull_request_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/comments/230487634"},"html":{"href":"https://github.com/virtual-kubelet/virtual-kubelet/pull/393#discussion_r230487634"},"pull_request":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393"}}},"pull_request":{"url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393","id":228011928,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI4MDExOTI4","html_url":"https://github.com/virtual-kubelet/virtual-kubelet/pull/393","diff_url":"https://github.com/virtual-kubelet/virtual-kubelet/pull/393.diff","patch_url":"https://github.com/virtual-kubelet/virtual-kubelet/pull/393.patch","issue_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues/393","number":393,"state":"open","locked":false,"title":"Serialize event handling per pod","user":{"login":"cpuguy83","id":799078,"node_id":"MDQ6VXNlcjc5OTA3OA==","avatar_url":"https://avatars3.githubusercontent.com/u/799078?v=4","gravatar_id":"","url":"https://api.github.com/users/cpuguy83","html_url":"https://github.com/cpuguy83","followers_url":"https://api.github.com/users/cpuguy83/followers","following_url":"https://api.github.com/users/cpuguy83/following{/other_user}","gists_url":"https://api.github.com/users/cpuguy83/gists{/gist_id}","starred_url":"https://api.github.com/users/cpuguy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpuguy83/subscriptions","organizations_url":"https://api.github.com/users/cpuguy83/orgs","repos_url":"https://api.github.com/users/cpuguy83/repos","events_url":"https://api.github.com/users/cpuguy83/events{/privacy}","received_events_url":"https://api.github.com/users/cpuguy83/received_events","type":"User","site_admin":false},"body":"Before this change all pod events are handling concurrently. This means\r\nthat multiple events for the same pod can be handled at the same time\r\nand end up in a race where they may be processed in the incorrect order.\r\n\r\nAn easy way to reproduce this issue is to fire up VK, add some pods, then suspend it\r\n(ctrl+z) for a minute or two, then resume. A blast of events will come\r\nfrom k8s and cause out of order handling. This will cause duplicate pods\r\nto be created in the provider that can never be cleaned up (by VK).\r\n\r\nThis change uses a mutex keyed on pod namespace+name to ensure that only\r\none event is handled at a time and as an added check to ensure that the\r\npod does not already exist in the resource manager before triggering a\r\npod create.","created_at":"2018-11-02T17:44:55Z","updated_at":"2018-11-02T19:44:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fea5fb74b44a1785cbb3b2c6c946ed0e811e2622","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393/commits","review_comments_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393/comments","review_comment_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues/393/comments","statuses_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/statuses/51725e1c29430d584dda2bec8f42296e90fbfb4b","head":{"label":"cpuguy83:serialize_pod_handling","ref":"serialize_pod_handling","sha":"51725e1c29430d584dda2bec8f42296e90fbfb4b","user":{"login":"cpuguy83","id":799078,"node_id":"MDQ6VXNlcjc5OTA3OA==","avatar_url":"https://avatars3.githubusercontent.com/u/799078?v=4","gravatar_id":"","url":"https://api.github.com/users/cpuguy83","html_url":"https://github.com/cpuguy83","followers_url":"https://api.github.com/users/cpuguy83/followers","following_url":"https://api.github.com/users/cpuguy83/following{/other_user}","gists_url":"https://api.github.com/users/cpuguy83/gists{/gist_id}","starred_url":"https://api.github.com/users/cpuguy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpuguy83/subscriptions","organizations_url":"https://api.github.com/users/cpuguy83/orgs","repos_url":"https://api.github.com/users/cpuguy83/repos","events_url":"https://api.github.com/users/cpuguy83/events{/privacy}","received_events_url":"https://api.github.com/users/cpuguy83/received_events","type":"User","site_admin":false},"repo":{"id":142049507,"node_id":"MDEwOlJlcG9zaXRvcnkxNDIwNDk1MDc=","name":"virtual-kubelet","full_name":"cpuguy83/virtual-kubelet","private":false,"owner":{"login":"cpuguy83","id":799078,"node_id":"MDQ6VXNlcjc5OTA3OA==","avatar_url":"https://avatars3.githubusercontent.com/u/799078?v=4","gravatar_id":"","url":"https://api.github.com/users/cpuguy83","html_url":"https://github.com/cpuguy83","followers_url":"https://api.github.com/users/cpuguy83/followers","following_url":"https://api.github.com/users/cpuguy83/following{/other_user}","gists_url":"https://api.github.com/users/cpuguy83/gists{/gist_id}","starred_url":"https://api.github.com/users/cpuguy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpuguy83/subscriptions","organizations_url":"https://api.github.com/users/cpuguy83/orgs","repos_url":"https://api.github.com/users/cpuguy83/repos","events_url":"https://api.github.com/users/cpuguy83/events{/privacy}","received_events_url":"https://api.github.com/users/cpuguy83/received_events","type":"User","site_admin":false},"html_url":"https://github.com/cpuguy83/virtual-kubelet","description":"Virtual Kubelet is an open source Kubernetes kubelet implementation.","fork":true,"url":"https://api.github.com/repos/cpuguy83/virtual-kubelet","forks_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/forks","keys_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/teams","hooks_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/hooks","issue_events_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/issues/events{/number}","events_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/events","assignees_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/assignees{/user}","branches_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/branches{/branch}","tags_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/tags","blobs_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/git/refs{/sha}","trees_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/statuses/{sha}","languages_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/languages","stargazers_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/stargazers","contributors_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/contributors","subscribers_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/subscribers","subscription_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/subscription","commits_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/commits{/sha}","git_commits_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/git/commits{/sha}","comments_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/comments{/number}","issue_comment_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/issues/comments{/number}","contents_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/contents/{+path}","compare_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/merges","archive_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/downloads","issues_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/issues{/number}","pulls_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/pulls{/number}","milestones_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/milestones{/number}","notifications_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/labels{/name}","releases_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/releases{/id}","deployments_url":"https://api.github.com/repos/cpuguy83/virtual-kubelet/deployments","created_at":"2018-07-23T17:52:48Z","updated_at":"2018-11-01T21:45:24Z","pushed_at":"2018-11-02T19:42:53Z","git_url":"git://github.com/cpuguy83/virtual-kubelet.git","ssh_url":"git@github.com:cpuguy83/virtual-kubelet.git","clone_url":"https://github.com/cpuguy83/virtual-kubelet.git","svn_url":"https://github.com/cpuguy83/virtual-kubelet","homepage":"","size":55097,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"virtual-kubelet:master","ref":"master","sha":"4edd39a8ef2d7f9571460f45f170d2f33e084b49","user":{"login":"virtual-kubelet","id":34250142,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0MjUwMTQy","avatar_url":"https://avatars2.githubusercontent.com/u/34250142?v=4","gravatar_id":"","url":"https://api.github.com/users/virtual-kubelet","html_url":"https://github.com/virtual-kubelet","followers_url":"https://api.github.com/users/virtual-kubelet/followers","following_url":"https://api.github.com/users/virtual-kubelet/following{/other_user}","gists_url":"https://api.github.com/users/virtual-kubelet/gists{/gist_id}","starred_url":"https://api.github.com/users/virtual-kubelet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/virtual-kubelet/subscriptions","organizations_url":"https://api.github.com/users/virtual-kubelet/orgs","repos_url":"https://api.github.com/users/virtual-kubelet/repos","events_url":"https://api.github.com/users/virtual-kubelet/events{/privacy}","received_events_url":"https://api.github.com/users/virtual-kubelet/received_events","type":"Organization","site_admin":false},"repo":{"id":113086028,"node_id":"MDEwOlJlcG9zaXRvcnkxMTMwODYwMjg=","name":"virtual-kubelet","full_name":"virtual-kubelet/virtual-kubelet","private":false,"owner":{"login":"virtual-kubelet","id":34250142,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0MjUwMTQy","avatar_url":"https://avatars2.githubusercontent.com/u/34250142?v=4","gravatar_id":"","url":"https://api.github.com/users/virtual-kubelet","html_url":"https://github.com/virtual-kubelet","followers_url":"https://api.github.com/users/virtual-kubelet/followers","following_url":"https://api.github.com/users/virtual-kubelet/following{/other_user}","gists_url":"https://api.github.com/users/virtual-kubelet/gists{/gist_id}","starred_url":"https://api.github.com/users/virtual-kubelet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/virtual-kubelet/subscriptions","organizations_url":"https://api.github.com/users/virtual-kubelet/orgs","repos_url":"https://api.github.com/users/virtual-kubelet/repos","events_url":"https://api.github.com/users/virtual-kubelet/events{/privacy}","received_events_url":"https://api.github.com/users/virtual-kubelet/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/virtual-kubelet/virtual-kubelet","description":"Virtual Kubelet is an open source Kubernetes kubelet implementation.","fork":false,"url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet","forks_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/forks","keys_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/teams","hooks_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/hooks","issue_events_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues/events{/number}","events_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/events","assignees_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/assignees{/user}","branches_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/branches{/branch}","tags_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/tags","blobs_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/git/refs{/sha}","trees_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/statuses/{sha}","languages_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/languages","stargazers_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/stargazers","contributors_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/contributors","subscribers_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/subscribers","subscription_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/subscription","commits_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/commits{/sha}","git_commits_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/git/commits{/sha}","comments_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/comments{/number}","issue_comment_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues/comments{/number}","contents_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/contents/{+path}","compare_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/merges","archive_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/downloads","issues_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues{/number}","pulls_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls{/number}","milestones_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/milestones{/number}","notifications_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/labels{/name}","releases_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/releases{/id}","deployments_url":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/deployments","created_at":"2017-12-04T19:32:57Z","updated_at":"2018-11-02T19:42:53Z","pushed_at":"2018-11-02T19:42:50Z","git_url":"git://github.com/virtual-kubelet/virtual-kubelet.git","ssh_url":"git@github.com:virtual-kubelet/virtual-kubelet.git","clone_url":"https://github.com/virtual-kubelet/virtual-kubelet.git","svn_url":"https://github.com/virtual-kubelet/virtual-kubelet","homepage":"","size":55085,"stargazers_count":1262,"watchers_count":1262,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":187,"mirror_url":null,"archived":false,"open_issues_count":90,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":187,"open_issues":90,"watchers":1262,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393"},"html":{"href":"https://github.com/virtual-kubelet/virtual-kubelet/pull/393"},"issue":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues/393"},"comments":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/issues/393/comments"},"review_comments":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393/comments"},"review_comment":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/pulls/393/commits"},"statuses":{"href":"https://api.github.com/repos/virtual-kubelet/virtual-kubelet/statuses/51725e1c29430d584dda2bec8f42296e90fbfb4b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"robbiezhang"}}