{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/vs-threading/pulls/comments/117308873","pull_request_review_id":39006481,"id":117308873,"diff_hunk":"@@ -465,7 +465,8 @@ private bool SynchronouslyBlockingThreadPool\n             get\n             {\n                 return (this.state & JoinableTaskFlags.StartedSynchronously) == JoinableTaskFlags.StartedSynchronously\n-                    && (this.state & JoinableTaskFlags.StartedOnMainThread) == JoinableTaskFlags.None;\n+                    && (this.state & JoinableTaskFlags.StartedOnMainThread) == JoinableTaskFlags.None\n+                    && (this.state & JoinableTaskFlags.CompleteRequested) != JoinableTaskFlags.CompleteRequested;","path":"src/Microsoft.VisualStudio.Threading.Shared/JoinableTask.cs","position":6,"original_position":6,"commit_id":"5728fd0bfa01dd5f1ffa6cb15d5099a92b85c5f6","original_commit_id":"5728fd0bfa01dd5f1ffa6cb15d5099a92b85c5f6","user":{"login":"AArnott","id":3548,"avatar_url":"https://avatars1.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"body":"Changed.","created_at":"2017-05-18T17:37:56Z","updated_at":"2017-05-18T17:37:56Z","html_url":"https://github.com/Microsoft/vs-threading/pull/116#discussion_r117308873","pull_request_url":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/vs-threading/pulls/comments/117308873"},"html":{"href":"https://github.com/Microsoft/vs-threading/pull/116#discussion_r117308873"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116","id":121328488,"html_url":"https://github.com/Microsoft/vs-threading/pull/116","diff_url":"https://github.com/Microsoft/vs-threading/pull/116.diff","patch_url":"https://github.com/Microsoft/vs-threading/pull/116.patch","issue_url":"https://api.github.com/repos/Microsoft/vs-threading/issues/116","number":116,"state":"open","locked":false,"title":"Fix two race conditions around JoinableTaskSynchronizationContext.Post","user":{"login":"AArnott","id":3548,"avatar_url":"https://avatars1.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"body":"When `JoinableTaskFactory.Run` is invoked from a background thread, and its delegate captures the `SynchronizationContext` and posts to it from another thread at about the same time as the JTF.Run delegate completes, two race conditions exist:\r\n\r\n1. `JoinableTaskSynchronizationContext.Post` checks `this.job!=null` before dereferencing it, but another thread sets it to null between the check and the dereference, leading to `NullReferenceException` being thrown from the `Post` method. This crashes Visual Studio. Issue #114. The fix for this is to capture the field as a local variable first. If the field changes in the middle, that's OK, because a completed `JoinableTask` knows how to transfer posted work to the threadpool or `JoinableTaskFactory`.\r\n1. When `JoinableTask.Post` executes it may add the posted work to `threadPoolQueue` after `JoinableTask.CompleteOnCurrentThread` has considered migrating that queue to the .NET ThreadPool as part of completing the task. With no one processing that queue, that delegate gets GC'd instead of scheduled and executed. Issue #115. The fix for this is to make our state-checking properties a bit more careful about saying whether JTF.Run is *still* blocking its calling thread. In the race condition case, these were reporting that the thread was blocked, even though JTF.Run had returned or was in the process of returning. By making these properties return false in this condition, the `JoinableTask.Post` method decides to skip its `threadPoolQueue` and go directly to the `ThreadPool` as required.\r\n\r\nFYI, we found #114 via crash dumps. I found #115 by accident while writing the unit test to repro #114. Yay, TDD!\r\n\r\nFixes #114 \r\nFixes #115 ","created_at":"2017-05-18T16:42:00Z","updated_at":"2017-05-18T17:37:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":{"login":"AArnott","id":3548,"avatar_url":"https://avatars1.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"assignees":[{"login":"AArnott","id":3548,"avatar_url":"https://avatars1.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"lifengl","id":11638466,"avatar_url":"https://avatars1.githubusercontent.com/u/11638466?v=3","gravatar_id":"","url":"https://api.github.com/users/lifengl","html_url":"https://github.com/lifengl","followers_url":"https://api.github.com/users/lifengl/followers","following_url":"https://api.github.com/users/lifengl/following{/other_user}","gists_url":"https://api.github.com/users/lifengl/gists{/gist_id}","starred_url":"https://api.github.com/users/lifengl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lifengl/subscriptions","organizations_url":"https://api.github.com/users/lifengl/orgs","repos_url":"https://api.github.com/users/lifengl/repos","events_url":"https://api.github.com/users/lifengl/events{/privacy}","received_events_url":"https://api.github.com/users/lifengl/received_events","type":"User","site_admin":false},{"login":"IlyaBiryukov","id":15989459,"avatar_url":"https://avatars2.githubusercontent.com/u/15989459?v=3","gravatar_id":"","url":"https://api.github.com/users/IlyaBiryukov","html_url":"https://github.com/IlyaBiryukov","followers_url":"https://api.github.com/users/IlyaBiryukov/followers","following_url":"https://api.github.com/users/IlyaBiryukov/following{/other_user}","gists_url":"https://api.github.com/users/IlyaBiryukov/gists{/gist_id}","starred_url":"https://api.github.com/users/IlyaBiryukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IlyaBiryukov/subscriptions","organizations_url":"https://api.github.com/users/IlyaBiryukov/orgs","repos_url":"https://api.github.com/users/IlyaBiryukov/repos","events_url":"https://api.github.com/users/IlyaBiryukov/events{/privacy}","received_events_url":"https://api.github.com/users/IlyaBiryukov/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116/commits","review_comments_url":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116/comments","review_comment_url":"https://api.github.com/repos/Microsoft/vs-threading/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/vs-threading/issues/116/comments","statuses_url":"https://api.github.com/repos/Microsoft/vs-threading/statuses/5728fd0bfa01dd5f1ffa6cb15d5099a92b85c5f6","head":{"label":"Microsoft:dev/andarno/fix114","ref":"dev/andarno/fix114","sha":"5728fd0bfa01dd5f1ffa6cb15d5099a92b85c5f6","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars1.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":70068171,"name":"vs-threading","full_name":"Microsoft/vs-threading","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars1.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/vs-threading","description":"The Microsoft.VisualStudio.Threading is a xplat library that provides many threading and synchronization primitives used in Visual Studio and other applications. ","fork":false,"url":"https://api.github.com/repos/Microsoft/vs-threading","forks_url":"https://api.github.com/repos/Microsoft/vs-threading/forks","keys_url":"https://api.github.com/repos/Microsoft/vs-threading/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/vs-threading/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/vs-threading/teams","hooks_url":"https://api.github.com/repos/Microsoft/vs-threading/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/vs-threading/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/vs-threading/events","assignees_url":"https://api.github.com/repos/Microsoft/vs-threading/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/vs-threading/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/vs-threading/tags","blobs_url":"https://api.github.com/repos/Microsoft/vs-threading/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/vs-threading/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/vs-threading/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/vs-threading/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/vs-threading/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/vs-threading/languages","stargazers_url":"https://api.github.com/repos/Microsoft/vs-threading/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/vs-threading/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/vs-threading/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/vs-threading/subscription","commits_url":"https://api.github.com/repos/Microsoft/vs-threading/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/vs-threading/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/vs-threading/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/vs-threading/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/vs-threading/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/vs-threading/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/vs-threading/merges","archive_url":"https://api.github.com/repos/Microsoft/vs-threading/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/vs-threading/downloads","issues_url":"https://api.github.com/repos/Microsoft/vs-threading/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/vs-threading/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/vs-threading/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/vs-threading/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/vs-threading/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/vs-threading/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/vs-threading/deployments","created_at":"2016-10-05T14:27:26Z","updated_at":"2017-05-17T12:41:36Z","pushed_at":"2017-05-18T16:42:44Z","git_url":"git://github.com/Microsoft/vs-threading.git","ssh_url":"git@github.com:Microsoft/vs-threading.git","clone_url":"https://github.com/Microsoft/vs-threading.git","svn_url":"https://github.com/Microsoft/vs-threading","homepage":null,"size":4713,"stargazers_count":102,"watchers_count":102,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":25,"forks":11,"open_issues":25,"watchers":102,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"f26e88b9dc0cc76935446d5ce17d09edb28c72d9","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars1.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":70068171,"name":"vs-threading","full_name":"Microsoft/vs-threading","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars1.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/vs-threading","description":"The Microsoft.VisualStudio.Threading is a xplat library that provides many threading and synchronization primitives used in Visual Studio and other applications. ","fork":false,"url":"https://api.github.com/repos/Microsoft/vs-threading","forks_url":"https://api.github.com/repos/Microsoft/vs-threading/forks","keys_url":"https://api.github.com/repos/Microsoft/vs-threading/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/vs-threading/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/vs-threading/teams","hooks_url":"https://api.github.com/repos/Microsoft/vs-threading/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/vs-threading/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/vs-threading/events","assignees_url":"https://api.github.com/repos/Microsoft/vs-threading/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/vs-threading/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/vs-threading/tags","blobs_url":"https://api.github.com/repos/Microsoft/vs-threading/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/vs-threading/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/vs-threading/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/vs-threading/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/vs-threading/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/vs-threading/languages","stargazers_url":"https://api.github.com/repos/Microsoft/vs-threading/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/vs-threading/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/vs-threading/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/vs-threading/subscription","commits_url":"https://api.github.com/repos/Microsoft/vs-threading/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/vs-threading/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/vs-threading/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/vs-threading/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/vs-threading/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/vs-threading/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/vs-threading/merges","archive_url":"https://api.github.com/repos/Microsoft/vs-threading/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/vs-threading/downloads","issues_url":"https://api.github.com/repos/Microsoft/vs-threading/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/vs-threading/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/vs-threading/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/vs-threading/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/vs-threading/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/vs-threading/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/vs-threading/deployments","created_at":"2016-10-05T14:27:26Z","updated_at":"2017-05-17T12:41:36Z","pushed_at":"2017-05-18T16:42:44Z","git_url":"git://github.com/Microsoft/vs-threading.git","ssh_url":"git@github.com:Microsoft/vs-threading.git","clone_url":"https://github.com/Microsoft/vs-threading.git","svn_url":"https://github.com/Microsoft/vs-threading","homepage":null,"size":4713,"stargazers_count":102,"watchers_count":102,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":25,"forks":11,"open_issues":25,"watchers":102,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116"},"html":{"href":"https://github.com/Microsoft/vs-threading/pull/116"},"issue":{"href":"https://api.github.com/repos/Microsoft/vs-threading/issues/116"},"comments":{"href":"https://api.github.com/repos/Microsoft/vs-threading/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/vs-threading/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/vs-threading/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/vs-threading/statuses/5728fd0bfa01dd5f1ffa6cb15d5099a92b85c5f6"}}}}
{"actor":{"display_login":"AArnott"}}