{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/comments/49159655","id":49159655,"diff_hunk":"@@ -253,9 +265,9 @@ private void ScheduleWrite()\n         // This is called on the libuv event loop\n         private void WriteAllPending()\n         {\n-            WriteContext writingContext;\n+            WriteContext writingContext = null;\n \n-            lock (_contextLock)\n+            if (Monitor.TryEnter(_contextLock))","path":"src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs","position":76,"original_position":76,"commit_id":"aa495480a2360ee4e4e2e106d8f98c65aa109f57","original_commit_id":"aa495480a2360ee4e4e2e106d8f98c65aa109f57","user":{"login":"cesarbs","id":924164,"avatar_url":"https://avatars.githubusercontent.com/u/924164?v=3","gravatar_id":"","url":"https://api.github.com/users/cesarbs","html_url":"https://github.com/cesarbs","followers_url":"https://api.github.com/users/cesarbs/followers","following_url":"https://api.github.com/users/cesarbs/following{/other_user}","gists_url":"https://api.github.com/users/cesarbs/gists{/gist_id}","starred_url":"https://api.github.com/users/cesarbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cesarbs/subscriptions","organizations_url":"https://api.github.com/users/cesarbs/orgs","repos_url":"https://api.github.com/users/cesarbs/repos","events_url":"https://api.github.com/users/cesarbs/events{/privacy}","received_events_url":"https://api.github.com/users/cesarbs/received_events","type":"User","site_admin":false},"body":"Why?","created_at":"2016-01-08T05:36:37Z","updated_at":"2016-01-08T05:36:37Z","html_url":"https://github.com/aspnet/KestrelHttpServer/pull/562#discussion_r49159655","pull_request_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562","_links":{"self":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/comments/49159655"},"html":{"href":"https://github.com/aspnet/KestrelHttpServer/pull/562#discussion_r49159655"},"pull_request":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562","id":55424582,"html_url":"https://github.com/aspnet/KestrelHttpServer/pull/562","diff_url":"https://github.com/aspnet/KestrelHttpServer/pull/562.diff","patch_url":"https://github.com/aspnet/KestrelHttpServer/pull/562.patch","issue_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/562","number":562,"state":"open","locked":false,"title":"Make all write operations atomic","user":{"login":"halter73","id":54385,"avatar_url":"https://avatars.githubusercontent.com/u/54385?v=3","gravatar_id":"","url":"https://api.github.com/users/halter73","html_url":"https://github.com/halter73","followers_url":"https://api.github.com/users/halter73/followers","following_url":"https://api.github.com/users/halter73/following{/other_user}","gists_url":"https://api.github.com/users/halter73/gists{/gist_id}","starred_url":"https://api.github.com/users/halter73/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halter73/subscriptions","organizations_url":"https://api.github.com/users/halter73/orgs","repos_url":"https://api.github.com/users/halter73/repos","events_url":"https://api.github.com/users/halter73/events{/privacy}","received_events_url":"https://api.github.com/users/halter73/received_events","type":"User","site_admin":false},"body":"This PR ensures that simultaneous calls to `SocketOutput.WriteAsync` won't result in a corrupted write.\r\n\r\nThis was mainly achieved by moving the `CopyFrom` call inside of `SocketOutput.WriteAsync` inside of the `_contenxtLock`. I also moved chunking down a layer inside of `SocketOutput`, so it could be protected by the same lock.\r\n\r\nI tested this change using both the plaintext benchmark and a modified LargeResponseSample that used small chunking, and in both cases the performance was nearly identical <1% to dev.\r\n\r\nWhen I first tried only moving `CopyFrom` inside of the lock, I saw performance degradation of a few percent. I was able to remedy this by using `Monitor.TryEnter` to avoid stalling libuv threads.","created_at":"2016-01-08T04:48:04Z","updated_at":"2016-01-08T05:36:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"99a5d5e04425e4c67758fa803735970dc9952c83","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562/commits","review_comments_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562/comments","review_comment_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/562/comments","statuses_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/statuses/aa495480a2360ee4e4e2e106d8f98c65aa109f57","head":{"label":"aspnet:shalter/lock-write","ref":"shalter/lock-write","sha":"aa495480a2360ee4e4e2e106d8f98c65aa109f57","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":20344662,"name":"KestrelHttpServer","full_name":"aspnet/KestrelHttpServer","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/KestrelHttpServer","description":"A web server for ASP.NET 5 based on libuv.","fork":false,"url":"https://api.github.com/repos/aspnet/KestrelHttpServer","forks_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/forks","keys_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/teams","hooks_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/hooks","issue_events_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/events","assignees_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/tags","blobs_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/languages","stargazers_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/stargazers","contributors_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/contributors","subscribers_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/subscribers","subscription_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/subscription","commits_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/merges","archive_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/downloads","issues_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/releases{/id}","created_at":"2014-05-30T22:46:28Z","updated_at":"2016-01-06T15:52:26Z","pushed_at":"2016-01-08T05:19:47Z","git_url":"git://github.com/aspnet/KestrelHttpServer.git","ssh_url":"git@github.com:aspnet/KestrelHttpServer.git","clone_url":"https://github.com/aspnet/KestrelHttpServer.git","svn_url":"https://github.com/aspnet/KestrelHttpServer","homepage":"","size":4153,"stargazers_count":553,"watchers_count":553,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":126,"mirror_url":null,"open_issues_count":64,"forks":126,"open_issues":64,"watchers":553,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"b82649123440f278d7d2afff36b2a71242608b0a","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":20344662,"name":"KestrelHttpServer","full_name":"aspnet/KestrelHttpServer","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/KestrelHttpServer","description":"A web server for ASP.NET 5 based on libuv.","fork":false,"url":"https://api.github.com/repos/aspnet/KestrelHttpServer","forks_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/forks","keys_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/teams","hooks_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/hooks","issue_events_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/events","assignees_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/tags","blobs_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/languages","stargazers_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/stargazers","contributors_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/contributors","subscribers_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/subscribers","subscription_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/subscription","commits_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/merges","archive_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/downloads","issues_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/KestrelHttpServer/releases{/id}","created_at":"2014-05-30T22:46:28Z","updated_at":"2016-01-06T15:52:26Z","pushed_at":"2016-01-08T05:19:47Z","git_url":"git://github.com/aspnet/KestrelHttpServer.git","ssh_url":"git@github.com:aspnet/KestrelHttpServer.git","clone_url":"https://github.com/aspnet/KestrelHttpServer.git","svn_url":"https://github.com/aspnet/KestrelHttpServer","homepage":"","size":4153,"stargazers_count":553,"watchers_count":553,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":126,"mirror_url":null,"open_issues_count":64,"forks":126,"open_issues":64,"watchers":553,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562"},"html":{"href":"https://github.com/aspnet/KestrelHttpServer/pull/562"},"issue":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/562"},"comments":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/issues/562/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/pulls/562/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/KestrelHttpServer/statuses/aa495480a2360ee4e4e2e106d8f98c65aa109f57"}}}}