{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/PTVS/pulls/comments/36477498","id":36477498,"diff_hunk":"@@ -177,34 +176,71 @@ internal SharedDatabaseState(Version languageVersion, string databaseDirectory,\n             var obj = ObjectType;\r\n             if (obj != null) {\r\n                 assign(obj);\r\n-            } else if (_objectTypeFixups != null) {\r\n-                _objectTypeFixups.Add(assign);\r\n-            } else {\r\n-                throw new InvalidOperationException(\"Cannot find builtin type 'object'\");\r\n+                return;\r\n             }\r\n+\r\n+            var fixups = _objectTypeFixups;\r\n+            if (fixups != null) {\r\n+                lock (fixups) {\r\n+                    // Ensure it was not changed while waiting for the lock\r\n+                    if (ReferenceEquals(_objectTypeFixups, fixups)) {\r\n+                        fixups.Add(assign);\r\n+                        return;\r\n+                    }\r\n+                }\r\n+\r\n+                // _objectTypeFixups changed, and it only changes to null, so we\r\n+                // should call assign directly\r\n+                obj = ObjectType;\r\n+                if (obj != null) {\r\n+                    assign(obj);\r\n+                    return;\r\n+                }\r\n+            } \r\n+\r\n+            throw new InvalidOperationException(\"Cannot find builtin type 'object'\");\r\n         }\r\n \r\n-        private void RunObjectTypeFixups() {\r\n-            if (_objectType == null) {\r\n-                _objectType = BuiltinModule.GetAnyMember(GetBuiltinTypeName(BuiltinTypeId.Object)) as IPythonType;\r\n-                if (_objectType != null) {\r\n-                    var fixups = _objectTypeFixups;\r\n-                    _objectTypeFixups = null;\r\n-                    if (fixups != null) {\r\n-                        foreach (var assign in fixups) {\r\n-                            assign(_objectType);\r\n-                        }\r\n+        private IPythonType RunObjectTypeFixups() {\r\n+            var objectType = _objectType;\r\n+            if (objectType == null) {\r\n+                var newObjectType = BuiltinModule.GetAnyMember(GetBuiltinTypeName(BuiltinTypeId.Object)) as IPythonType;\r\n+\r\n+                if (newObjectType == null) {\r\n+                    // No type available, so don't do fixups\r\n+                    return null;\r\n+                }\r\n+\r\n+                // Either set _objectType to newObjectType, or replace our local\r\n+                // objectType with whatever got there first\r\n+                objectType = Interlocked.CompareExchange(ref _objectType, newObjectType, null) ?? newObjectType;\r\n+            }\r\n+\r\n+            var fixups = _objectTypeFixups;\r\n+            if (fixups != null) {\r\n+                lock (fixups) {\r\n+                    if (!ReferenceEquals(_objectTypeFixups, fixups)) {\r\n+                        // _objectTypeFixups changed while we waited to lock\r\n+                        return objectType;\r","path":"Python/Product/Analysis/Interpreter/SharedDatabaseState.cs","position":89,"original_position":89,"commit_id":"f3dad22e08782cbb0f003f22a482ccbccde15751","original_commit_id":"f3dad22e08782cbb0f003f22a482ccbccde15751","user":{"login":"int19h","id":1175142,"avatar_url":"https://avatars.githubusercontent.com/u/1175142?v=3","gravatar_id":"","url":"https://api.github.com/users/int19h","html_url":"https://github.com/int19h","followers_url":"https://api.github.com/users/int19h/followers","following_url":"https://api.github.com/users/int19h/following{/other_user}","gists_url":"https://api.github.com/users/int19h/gists{/gist_id}","starred_url":"https://api.github.com/users/int19h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/int19h/subscriptions","organizations_url":"https://api.github.com/users/int19h/orgs","repos_url":"https://api.github.com/users/int19h/repos","events_url":"https://api.github.com/users/int19h/events{/privacy}","received_events_url":"https://api.github.com/users/int19h/received_events","type":"User","site_admin":false},"body":"Shouldn't this be a retry rather than instant return?","created_at":"2015-08-06T23:17:27Z","updated_at":"2015-08-06T23:17:27Z","html_url":"https://github.com/Microsoft/PTVS/pull/695#discussion_r36477498","pull_request_url":"https://api.github.com/repos/Microsoft/PTVS/pulls/695","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/PTVS/pulls/comments/36477498"},"html":{"href":"https://github.com/Microsoft/PTVS/pull/695#discussion_r36477498"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/PTVS/pulls/695"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/PTVS/pulls/695","id":41845244,"html_url":"https://github.com/Microsoft/PTVS/pull/695","diff_url":"https://github.com/Microsoft/PTVS/pull/695.diff","patch_url":"https://github.com/Microsoft/PTVS/pull/695.patch","issue_url":"https://api.github.com/repos/Microsoft/PTVS/issues/695","number":695,"state":"open","locked":false,"title":"Fixes #682 Race condition in AddObjectTypeFixup","user":{"login":"zooba","id":1693688,"avatar_url":"https://avatars.githubusercontent.com/u/1693688?v=3","gravatar_id":"","url":"https://api.github.com/users/zooba","html_url":"https://github.com/zooba","followers_url":"https://api.github.com/users/zooba/followers","following_url":"https://api.github.com/users/zooba/following{/other_user}","gists_url":"https://api.github.com/users/zooba/gists{/gist_id}","starred_url":"https://api.github.com/users/zooba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooba/subscriptions","organizations_url":"https://api.github.com/users/zooba/orgs","repos_url":"https://api.github.com/users/zooba/repos","events_url":"https://api.github.com/users/zooba/events{/privacy}","received_events_url":"https://api.github.com/users/zooba/received_events","type":"User","site_admin":false},"body":"Fixes #682 Race condition in AddObjectTypeFixup\r\nAdds double-checked locking (or equivalent) to fixups lists and object instance.\r\nImproves error handling when an 'object' type cannot be found\r\n\r\nPlease review the changes to SharedDatabaseState.cs carefully - they took a lot of thought and *should* cover all the potential races for the three variables now.","created_at":"2015-08-06T23:10:15Z","updated_at":"2015-08-06T23:17:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"48c18855ba15482b22f69f7d8b390a312a402287","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/PTVS/pulls/695/commits","review_comments_url":"https://api.github.com/repos/Microsoft/PTVS/pulls/695/comments","review_comment_url":"https://api.github.com/repos/Microsoft/PTVS/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/PTVS/issues/695/comments","statuses_url":"https://api.github.com/repos/Microsoft/PTVS/statuses/f3dad22e08782cbb0f003f22a482ccbccde15751","head":{"label":"zooba:issue-682","ref":"issue-682","sha":"f3dad22e08782cbb0f003f22a482ccbccde15751","user":{"login":"zooba","id":1693688,"avatar_url":"https://avatars.githubusercontent.com/u/1693688?v=3","gravatar_id":"","url":"https://api.github.com/users/zooba","html_url":"https://github.com/zooba","followers_url":"https://api.github.com/users/zooba/followers","following_url":"https://api.github.com/users/zooba/following{/other_user}","gists_url":"https://api.github.com/users/zooba/gists{/gist_id}","starred_url":"https://api.github.com/users/zooba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooba/subscriptions","organizations_url":"https://api.github.com/users/zooba/orgs","repos_url":"https://api.github.com/users/zooba/repos","events_url":"https://api.github.com/users/zooba/events{/privacy}","received_events_url":"https://api.github.com/users/zooba/received_events","type":"User","site_admin":false},"repo":{"id":34676763,"name":"PTVS","full_name":"zooba/PTVS","owner":{"login":"zooba","id":1693688,"avatar_url":"https://avatars.githubusercontent.com/u/1693688?v=3","gravatar_id":"","url":"https://api.github.com/users/zooba","html_url":"https://github.com/zooba","followers_url":"https://api.github.com/users/zooba/followers","following_url":"https://api.github.com/users/zooba/following{/other_user}","gists_url":"https://api.github.com/users/zooba/gists{/gist_id}","starred_url":"https://api.github.com/users/zooba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooba/subscriptions","organizations_url":"https://api.github.com/users/zooba/orgs","repos_url":"https://api.github.com/users/zooba/repos","events_url":"https://api.github.com/users/zooba/events{/privacy}","received_events_url":"https://api.github.com/users/zooba/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zooba/PTVS","description":"Python Tools for Visual Studio","fork":true,"url":"https://api.github.com/repos/zooba/PTVS","forks_url":"https://api.github.com/repos/zooba/PTVS/forks","keys_url":"https://api.github.com/repos/zooba/PTVS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zooba/PTVS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zooba/PTVS/teams","hooks_url":"https://api.github.com/repos/zooba/PTVS/hooks","issue_events_url":"https://api.github.com/repos/zooba/PTVS/issues/events{/number}","events_url":"https://api.github.com/repos/zooba/PTVS/events","assignees_url":"https://api.github.com/repos/zooba/PTVS/assignees{/user}","branches_url":"https://api.github.com/repos/zooba/PTVS/branches{/branch}","tags_url":"https://api.github.com/repos/zooba/PTVS/tags","blobs_url":"https://api.github.com/repos/zooba/PTVS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zooba/PTVS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zooba/PTVS/git/refs{/sha}","trees_url":"https://api.github.com/repos/zooba/PTVS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zooba/PTVS/statuses/{sha}","languages_url":"https://api.github.com/repos/zooba/PTVS/languages","stargazers_url":"https://api.github.com/repos/zooba/PTVS/stargazers","contributors_url":"https://api.github.com/repos/zooba/PTVS/contributors","subscribers_url":"https://api.github.com/repos/zooba/PTVS/subscribers","subscription_url":"https://api.github.com/repos/zooba/PTVS/subscription","commits_url":"https://api.github.com/repos/zooba/PTVS/commits{/sha}","git_commits_url":"https://api.github.com/repos/zooba/PTVS/git/commits{/sha}","comments_url":"https://api.github.com/repos/zooba/PTVS/comments{/number}","issue_comment_url":"https://api.github.com/repos/zooba/PTVS/issues/comments{/number}","contents_url":"https://api.github.com/repos/zooba/PTVS/contents/{+path}","compare_url":"https://api.github.com/repos/zooba/PTVS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zooba/PTVS/merges","archive_url":"https://api.github.com/repos/zooba/PTVS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zooba/PTVS/downloads","issues_url":"https://api.github.com/repos/zooba/PTVS/issues{/number}","pulls_url":"https://api.github.com/repos/zooba/PTVS/pulls{/number}","milestones_url":"https://api.github.com/repos/zooba/PTVS/milestones{/number}","notifications_url":"https://api.github.com/repos/zooba/PTVS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zooba/PTVS/labels{/name}","releases_url":"https://api.github.com/repos/zooba/PTVS/releases{/id}","created_at":"2015-04-27T16:05:59Z","updated_at":"2015-05-05T16:35:34Z","pushed_at":"2015-08-06T23:10:33Z","git_url":"git://github.com/zooba/PTVS.git","ssh_url":"git@github.com:zooba/PTVS.git","clone_url":"https://github.com/zooba/PTVS.git","svn_url":"https://github.com/zooba/PTVS","homepage":"https://microsoft.github.io/PTVS","size":136968,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"758288e7b319bf6f2cb5dfebf9fa775d2a56d4b8","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.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":32487763,"name":"PTVS","full_name":"Microsoft/PTVS","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.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/PTVS","description":"Python Tools for Visual Studio","fork":false,"url":"https://api.github.com/repos/Microsoft/PTVS","forks_url":"https://api.github.com/repos/Microsoft/PTVS/forks","keys_url":"https://api.github.com/repos/Microsoft/PTVS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/PTVS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/PTVS/teams","hooks_url":"https://api.github.com/repos/Microsoft/PTVS/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/PTVS/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/PTVS/events","assignees_url":"https://api.github.com/repos/Microsoft/PTVS/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/PTVS/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/PTVS/tags","blobs_url":"https://api.github.com/repos/Microsoft/PTVS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/PTVS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/PTVS/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/PTVS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/PTVS/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/PTVS/languages","stargazers_url":"https://api.github.com/repos/Microsoft/PTVS/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/PTVS/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/PTVS/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/PTVS/subscription","commits_url":"https://api.github.com/repos/Microsoft/PTVS/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/PTVS/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/PTVS/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/PTVS/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/PTVS/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/PTVS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/PTVS/merges","archive_url":"https://api.github.com/repos/Microsoft/PTVS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/PTVS/downloads","issues_url":"https://api.github.com/repos/Microsoft/PTVS/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/PTVS/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/PTVS/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/PTVS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/PTVS/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/PTVS/releases{/id}","created_at":"2015-03-18T22:30:53Z","updated_at":"2015-08-06T22:53:00Z","pushed_at":"2015-08-06T23:10:32Z","git_url":"git://github.com/Microsoft/PTVS.git","ssh_url":"git@github.com:Microsoft/PTVS.git","clone_url":"https://github.com/Microsoft/PTVS.git","svn_url":"https://github.com/Microsoft/PTVS","homepage":"https://microsoft.github.io/PTVS","size":156270,"stargazers_count":443,"watchers_count":443,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":83,"mirror_url":null,"open_issues_count":273,"forks":83,"open_issues":273,"watchers":443,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/PTVS/pulls/695"},"html":{"href":"https://github.com/Microsoft/PTVS/pull/695"},"issue":{"href":"https://api.github.com/repos/Microsoft/PTVS/issues/695"},"comments":{"href":"https://api.github.com/repos/Microsoft/PTVS/issues/695/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/PTVS/pulls/695/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/PTVS/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/PTVS/pulls/695/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/PTVS/statuses/f3dad22e08782cbb0f003f22a482ccbccde15751"}}}}