{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/azure-storage-net/pulls/comments/153218219","pull_request_review_id":79191912,"id":153218219,"diff_hunk":"@@ -97,6 +98,14 @@ public bool ShouldRetry(int currentRetryCount, int statusCode, Exception lastExc\n             return false;\n         }\n \n+        private double CalculateIncrement(int currentRetryCount)\n+        {\n+            lock (randomLock)","path":"Lib/Common/RetryPolicies/ExponentialRetry.cs","position":25,"original_position":25,"commit_id":"5bb3617b5c5b7a1c221ff9ccf4f3e2108adb3412","original_commit_id":"5bb3617b5c5b7a1c221ff9ccf4f3e2108adb3412","user":{"login":"danielmarbach","id":174258,"avatar_url":"https://avatars1.githubusercontent.com/u/174258?v=4","gravatar_id":"","url":"https://api.github.com/users/danielmarbach","html_url":"https://github.com/danielmarbach","followers_url":"https://api.github.com/users/danielmarbach/followers","following_url":"https://api.github.com/users/danielmarbach/following{/other_user}","gists_url":"https://api.github.com/users/danielmarbach/gists{/gist_id}","starred_url":"https://api.github.com/users/danielmarbach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielmarbach/subscriptions","organizations_url":"https://api.github.com/users/danielmarbach/orgs","repos_url":"https://api.github.com/users/danielmarbach/repos","events_url":"https://api.github.com/users/danielmarbach/events{/privacy}","received_events_url":"https://api.github.com/users/danielmarbach/received_events","type":"User","site_admin":false},"body":"Why not use\r\n\r\n```\r\npublic static class StaticRandom\r\n{\r\n    static int seed = Environment.TickCount;\r\n\r\n    static readonly ThreadLocal<Random> random =\r\n        new ThreadLocal<Random>(() => new Random(Interlocked.Increment(ref seed)));\r\n\r\n    public static int Rand()\r\n    {\r\n        return random.Value.Next();\r\n    }\r\n}\r\n```\r\n\r\nhttps://stackoverflow.com/questions/19270507/correct-way-to-use-random-in-multithread-application\r\n\r\nto avoid lock?\r\n","created_at":"2017-11-27T14:54:41Z","updated_at":"2017-11-27T14:54:41Z","html_url":"https://github.com/Azure/azure-storage-net/pull/529#discussion_r153218219","pull_request_url":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-storage-net/pulls/comments/153218219"},"html":{"href":"https://github.com/Azure/azure-storage-net/pull/529#discussion_r153218219"},"pull_request":{"href":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529"}}},"pull_request":{"url":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529","id":138976287,"html_url":"https://github.com/Azure/azure-storage-net/pull/529","diff_url":"https://github.com/Azure/azure-storage-net/pull/529.diff","patch_url":"https://github.com/Azure/azure-storage-net/pull/529.patch","issue_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/529","number":529,"state":"open","locked":false,"title":"Fix misuse of System.Random in ExponentialRetry.cs","user":{"login":"jon-couloir","id":31550805,"avatar_url":"https://avatars0.githubusercontent.com/u/31550805?v=4","gravatar_id":"","url":"https://api.github.com/users/jon-couloir","html_url":"https://github.com/jon-couloir","followers_url":"https://api.github.com/users/jon-couloir/followers","following_url":"https://api.github.com/users/jon-couloir/following{/other_user}","gists_url":"https://api.github.com/users/jon-couloir/gists{/gist_id}","starred_url":"https://api.github.com/users/jon-couloir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jon-couloir/subscriptions","organizations_url":"https://api.github.com/users/jon-couloir/orgs","repos_url":"https://api.github.com/users/jon-couloir/repos","events_url":"https://api.github.com/users/jon-couloir/events{/privacy}","received_events_url":"https://api.github.com/users/jon-couloir/received_events","type":"User","site_admin":false},"body":"Changed the random instance to be created at the class level. This prevents multiple calls to the ShouldRetry instance in the same Environment.TickCount period (~15 milliseconds) receiving the exact same GetNext() values from the random instance. This random needs to be protected with a lock, as System.Random is not threadsafe (this is a very simple threadsafe implementation, for high concurrency there are more performant implementations of threadsafe random access at the cost of higher complexity)\r\n\r\ne.g. see https://blogs.msdn.microsoft.com/pfxteam/2009/02/19/getting-random-numbers-in-a-thread-safe-way/","created_at":"2017-09-01T21:25:34Z","updated_at":"2017-11-27T14:54:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19a08258d1fcfef298eca1544c018ef622d142da","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529/commits","review_comments_url":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529/comments","review_comment_url":"https://api.github.com/repos/Azure/azure-storage-net/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/529/comments","statuses_url":"https://api.github.com/repos/Azure/azure-storage-net/statuses/5bb3617b5c5b7a1c221ff9ccf4f3e2108adb3412","head":{"label":"jon-couloir:FixMisuseOfRandomInExponentialRetry","ref":"FixMisuseOfRandomInExponentialRetry","sha":"5bb3617b5c5b7a1c221ff9ccf4f3e2108adb3412","user":{"login":"jon-couloir","id":31550805,"avatar_url":"https://avatars0.githubusercontent.com/u/31550805?v=4","gravatar_id":"","url":"https://api.github.com/users/jon-couloir","html_url":"https://github.com/jon-couloir","followers_url":"https://api.github.com/users/jon-couloir/followers","following_url":"https://api.github.com/users/jon-couloir/following{/other_user}","gists_url":"https://api.github.com/users/jon-couloir/gists{/gist_id}","starred_url":"https://api.github.com/users/jon-couloir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jon-couloir/subscriptions","organizations_url":"https://api.github.com/users/jon-couloir/orgs","repos_url":"https://api.github.com/users/jon-couloir/repos","events_url":"https://api.github.com/users/jon-couloir/events{/privacy}","received_events_url":"https://api.github.com/users/jon-couloir/received_events","type":"User","site_admin":false},"repo":{"id":102153586,"name":"azure-storage-net","full_name":"jon-couloir/azure-storage-net","owner":{"login":"jon-couloir","id":31550805,"avatar_url":"https://avatars0.githubusercontent.com/u/31550805?v=4","gravatar_id":"","url":"https://api.github.com/users/jon-couloir","html_url":"https://github.com/jon-couloir","followers_url":"https://api.github.com/users/jon-couloir/followers","following_url":"https://api.github.com/users/jon-couloir/following{/other_user}","gists_url":"https://api.github.com/users/jon-couloir/gists{/gist_id}","starred_url":"https://api.github.com/users/jon-couloir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jon-couloir/subscriptions","organizations_url":"https://api.github.com/users/jon-couloir/orgs","repos_url":"https://api.github.com/users/jon-couloir/repos","events_url":"https://api.github.com/users/jon-couloir/events{/privacy}","received_events_url":"https://api.github.com/users/jon-couloir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jon-couloir/azure-storage-net","description":"Microsoft Azure Storage Libraries for .NET","fork":true,"url":"https://api.github.com/repos/jon-couloir/azure-storage-net","forks_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/forks","keys_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/teams","hooks_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/hooks","issue_events_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/issues/events{/number}","events_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/events","assignees_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/assignees{/user}","branches_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/branches{/branch}","tags_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/tags","blobs_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/git/refs{/sha}","trees_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/statuses/{sha}","languages_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/languages","stargazers_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/stargazers","contributors_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/contributors","subscribers_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/subscribers","subscription_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/subscription","commits_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/commits{/sha}","git_commits_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/git/commits{/sha}","comments_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/comments{/number}","issue_comment_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/issues/comments{/number}","contents_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/contents/{+path}","compare_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/merges","archive_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/downloads","issues_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/issues{/number}","pulls_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/pulls{/number}","milestones_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/milestones{/number}","notifications_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/labels{/name}","releases_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/releases{/id}","deployments_url":"https://api.github.com/repos/jon-couloir/azure-storage-net/deployments","created_at":"2017-09-01T21:14:18Z","updated_at":"2017-09-01T21:14:23Z","pushed_at":"2017-09-01T21:58:25Z","git_url":"git://github.com/jon-couloir/azure-storage-net.git","ssh_url":"git@github.com:jon-couloir/azure-storage-net.git","clone_url":"https://github.com/jon-couloir/azure-storage-net.git","svn_url":"https://github.com/jon-couloir/azure-storage-net","homepage":"","size":40240,"stargazers_count":0,"watchers_count":0,"language":"C#","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,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Azure:master","ref":"master","sha":"7be6a470cf07c0db3a97f214d139bfe9cf5f623b","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":13808889,"name":"azure-storage-net","full_name":"Azure/azure-storage-net","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/azure-storage-net","description":"Microsoft Azure Storage Libraries for .NET","fork":false,"url":"https://api.github.com/repos/Azure/azure-storage-net","forks_url":"https://api.github.com/repos/Azure/azure-storage-net/forks","keys_url":"https://api.github.com/repos/Azure/azure-storage-net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/azure-storage-net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/azure-storage-net/teams","hooks_url":"https://api.github.com/repos/Azure/azure-storage-net/hooks","issue_events_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/azure-storage-net/events","assignees_url":"https://api.github.com/repos/Azure/azure-storage-net/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/azure-storage-net/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/azure-storage-net/tags","blobs_url":"https://api.github.com/repos/Azure/azure-storage-net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/azure-storage-net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/azure-storage-net/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/azure-storage-net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/azure-storage-net/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/azure-storage-net/languages","stargazers_url":"https://api.github.com/repos/Azure/azure-storage-net/stargazers","contributors_url":"https://api.github.com/repos/Azure/azure-storage-net/contributors","subscribers_url":"https://api.github.com/repos/Azure/azure-storage-net/subscribers","subscription_url":"https://api.github.com/repos/Azure/azure-storage-net/subscription","commits_url":"https://api.github.com/repos/Azure/azure-storage-net/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/azure-storage-net/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/azure-storage-net/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/azure-storage-net/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/azure-storage-net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/azure-storage-net/merges","archive_url":"https://api.github.com/repos/Azure/azure-storage-net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/azure-storage-net/downloads","issues_url":"https://api.github.com/repos/Azure/azure-storage-net/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/azure-storage-net/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/azure-storage-net/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/azure-storage-net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/azure-storage-net/labels{/name}","releases_url":"https://api.github.com/repos/Azure/azure-storage-net/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/azure-storage-net/deployments","created_at":"2013-10-23T16:57:29Z","updated_at":"2017-11-26T17:59:52Z","pushed_at":"2017-11-27T14:45:00Z","git_url":"git://github.com/Azure/azure-storage-net.git","ssh_url":"git@github.com:Azure/azure-storage-net.git","clone_url":"https://github.com/Azure/azure-storage-net.git","svn_url":"https://github.com/Azure/azure-storage-net","homepage":"","size":40880,"stargazers_count":283,"watchers_count":283,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":233,"mirror_url":null,"archived":false,"open_issues_count":78,"forks":233,"open_issues":78,"watchers":283,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529"},"html":{"href":"https://github.com/Azure/azure-storage-net/pull/529"},"issue":{"href":"https://api.github.com/repos/Azure/azure-storage-net/issues/529"},"comments":{"href":"https://api.github.com/repos/Azure/azure-storage-net/issues/529/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/azure-storage-net/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/azure-storage-net/pulls/529/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/azure-storage-net/statuses/5bb3617b5c5b7a1c221ff9ccf4f3e2108adb3412"}},"author_association":"NONE"}}
{"actor":{"display_login":"danielmarbach"}}