{"action":"created","comment":{"url":"https://api.github.com/repos/docker/distribution/pulls/comments/35936861","id":35936861,"diff_hunk":"@@ -15,3 +19,38 @@ func closeResources(handler http.Handler, closers ...io.Closer) http.Handler {\n \t\thandler.ServeHTTP(w, r)\n \t})\n }\n+\n+// copyFullPayload copies the payload of a HTTP request to destWriter. If it\n+// receives less content than expected, and the client disconnected during the\n+// upload, it avoids sending a 400 error to keep the logs cleaner.\n+func copyFullPayload(responseWriter http.ResponseWriter, r *http.Request, destWriter io.Writer, context ctxu.Context, action string, errSlice *errcode.Errors) error {\n+\t// Get a channel that tells us if the client disconnects\n+\tvar clientClosed <-chan bool\n+\tif notifier, ok := responseWriter.(http.CloseNotifier); ok {\n+\t\tclientClosed = notifier.CloseNotify()\n+\t} else {\n+\t\tpanic(\"the ResponseWriter does not implement CloseNotifier\")\n+\t}\n+\n+\t// Read in the data, if any.\n+\tcopied, err := io.Copy(destWriter, r.Body)\n+\tif clientClosed != nil && (err != nil || (r.ContentLength > 0 && copied < r.ContentLength)) {\n+\t\t// Didn't recieve as much content as expected. Did the client\n+\t\t// disconnect during the request? If so, avoid returning a 400\n+\t\t// error to keep the logs cleaner.\n+\t\tselect {\n+\t\tcase <-clientClosed:\n+\t\t\tctxu.GetLogger(context).Error(\"client disconnected during \" + action)\n+\t\t\treturn errors.New(\"client disconnected\")","path":"registry/handlers/helpers.go","position":39,"original_position":39,"commit_id":"764c2ae6f56ec839d0d3164d9750fc3e6038071c","original_commit_id":"764c2ae6f56ec839d0d3164d9750fc3e6038071c","user":{"login":"aaronlehmann","id":10601430,"avatar_url":"https://avatars.githubusercontent.com/u/10601430?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronlehmann","html_url":"https://github.com/aaronlehmann","followers_url":"https://api.github.com/users/aaronlehmann/followers","following_url":"https://api.github.com/users/aaronlehmann/following{/other_user}","gists_url":"https://api.github.com/users/aaronlehmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronlehmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronlehmann/subscriptions","organizations_url":"https://api.github.com/users/aaronlehmann/orgs","repos_url":"https://api.github.com/users/aaronlehmann/repos","events_url":"https://api.github.com/users/aaronlehmann/events{/privacy}","received_events_url":"https://api.github.com/users/aaronlehmann/received_events","type":"User","site_admin":false},"body":"IMHO we don't need one. The caller only checks if there was an error or not; it doesn't make any use of it. I thought about making this function return a boolean, but I thought it was more idiomatic to return an error value.","created_at":"2015-07-31T00:26:24Z","updated_at":"2015-07-31T00:26:24Z","html_url":"https://github.com/docker/distribution/pull/763#discussion_r35936861","pull_request_url":"https://api.github.com/repos/docker/distribution/pulls/763","_links":{"self":{"href":"https://api.github.com/repos/docker/distribution/pulls/comments/35936861"},"html":{"href":"https://github.com/docker/distribution/pull/763#discussion_r35936861"},"pull_request":{"href":"https://api.github.com/repos/docker/distribution/pulls/763"}}},"pull_request":{"url":"https://api.github.com/repos/docker/distribution/pulls/763","id":40934898,"html_url":"https://github.com/docker/distribution/pull/763","diff_url":"https://github.com/docker/distribution/pull/763.diff","patch_url":"https://github.com/docker/distribution/pull/763.patch","issue_url":"https://api.github.com/repos/docker/distribution/issues/763","number":763,"state":"open","locked":false,"title":"Use CloseNotifier to supress spurious HTTP 400 errors on early disconnect","user":{"login":"aaronlehmann","id":10601430,"avatar_url":"https://avatars.githubusercontent.com/u/10601430?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronlehmann","html_url":"https://github.com/aaronlehmann","followers_url":"https://api.github.com/users/aaronlehmann/followers","following_url":"https://api.github.com/users/aaronlehmann/following{/other_user}","gists_url":"https://api.github.com/users/aaronlehmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronlehmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronlehmann/subscriptions","organizations_url":"https://api.github.com/users/aaronlehmann/orgs","repos_url":"https://api.github.com/users/aaronlehmann/repos","events_url":"https://api.github.com/users/aaronlehmann/events{/privacy}","received_events_url":"https://api.github.com/users/aaronlehmann/received_events","type":"User","site_admin":false},"body":"When a client disconnects without completing a HTTP request, we were attempting to process the partial request, which usually leads to a 400 error. These errors can pollute the logs and make it more difficult to track down real bugs.\r\n    \r\nThis change uses CloseNotifier to detect disconnects. In combination with checking Content-Length, we can detect a disconnect before sending the full payload, and avoid logging a 400 error.\r\n\r\nThis logic is only applied to PUT, POST, and PATCH endpoints, as these are the places where disconnects during a request are most likely to happen.","created_at":"2015-07-27T18:38:06Z","updated_at":"2015-07-31T00:26:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f9ce1afd7c437d20e43f9283436c401815bc2ed","assignee":{"login":"aaronlehmann","id":10601430,"avatar_url":"https://avatars.githubusercontent.com/u/10601430?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronlehmann","html_url":"https://github.com/aaronlehmann","followers_url":"https://api.github.com/users/aaronlehmann/followers","following_url":"https://api.github.com/users/aaronlehmann/following{/other_user}","gists_url":"https://api.github.com/users/aaronlehmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronlehmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronlehmann/subscriptions","organizations_url":"https://api.github.com/users/aaronlehmann/orgs","repos_url":"https://api.github.com/users/aaronlehmann/repos","events_url":"https://api.github.com/users/aaronlehmann/events{/privacy}","received_events_url":"https://api.github.com/users/aaronlehmann/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/docker/distribution/milestones/8","html_url":"https://github.com/docker/distribution/milestones/Registry/2.1","labels_url":"https://api.github.com/repos/docker/distribution/milestones/8/labels","id":1026598,"number":8,"title":"Registry/2.1","description":"Items in this roadmap will be part of the registry 2.1 release.","creator":{"login":"stevvooe","id":120601,"avatar_url":"https://avatars.githubusercontent.com/u/120601?v=3","gravatar_id":"","url":"https://api.github.com/users/stevvooe","html_url":"https://github.com/stevvooe","followers_url":"https://api.github.com/users/stevvooe/followers","following_url":"https://api.github.com/users/stevvooe/following{/other_user}","gists_url":"https://api.github.com/users/stevvooe/gists{/gist_id}","starred_url":"https://api.github.com/users/stevvooe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevvooe/subscriptions","organizations_url":"https://api.github.com/users/stevvooe/orgs","repos_url":"https://api.github.com/users/stevvooe/repos","events_url":"https://api.github.com/users/stevvooe/events{/privacy}","received_events_url":"https://api.github.com/users/stevvooe/received_events","type":"User","site_admin":false},"open_issues":25,"closed_issues":169,"state":"open","created_at":"2015-03-18T04:15:41Z","updated_at":"2015-07-30T23:41:14Z","due_on":"2015-08-04T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/docker/distribution/pulls/763/commits","review_comments_url":"https://api.github.com/repos/docker/distribution/pulls/763/comments","review_comment_url":"https://api.github.com/repos/docker/distribution/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/distribution/issues/763/comments","statuses_url":"https://api.github.com/repos/docker/distribution/statuses/764c2ae6f56ec839d0d3164d9750fc3e6038071c","head":{"label":"aaronlehmann:close-notifier","ref":"close-notifier","sha":"764c2ae6f56ec839d0d3164d9750fc3e6038071c","user":{"login":"aaronlehmann","id":10601430,"avatar_url":"https://avatars.githubusercontent.com/u/10601430?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronlehmann","html_url":"https://github.com/aaronlehmann","followers_url":"https://api.github.com/users/aaronlehmann/followers","following_url":"https://api.github.com/users/aaronlehmann/following{/other_user}","gists_url":"https://api.github.com/users/aaronlehmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronlehmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronlehmann/subscriptions","organizations_url":"https://api.github.com/users/aaronlehmann/orgs","repos_url":"https://api.github.com/users/aaronlehmann/repos","events_url":"https://api.github.com/users/aaronlehmann/events{/privacy}","received_events_url":"https://api.github.com/users/aaronlehmann/received_events","type":"User","site_admin":false},"repo":{"id":38719418,"name":"distribution","full_name":"aaronlehmann/distribution","owner":{"login":"aaronlehmann","id":10601430,"avatar_url":"https://avatars.githubusercontent.com/u/10601430?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronlehmann","html_url":"https://github.com/aaronlehmann","followers_url":"https://api.github.com/users/aaronlehmann/followers","following_url":"https://api.github.com/users/aaronlehmann/following{/other_user}","gists_url":"https://api.github.com/users/aaronlehmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronlehmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronlehmann/subscriptions","organizations_url":"https://api.github.com/users/aaronlehmann/orgs","repos_url":"https://api.github.com/users/aaronlehmann/repos","events_url":"https://api.github.com/users/aaronlehmann/events{/privacy}","received_events_url":"https://api.github.com/users/aaronlehmann/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aaronlehmann/distribution","description":"The Docker toolset to pack, ship, store, and deliver content","fork":true,"url":"https://api.github.com/repos/aaronlehmann/distribution","forks_url":"https://api.github.com/repos/aaronlehmann/distribution/forks","keys_url":"https://api.github.com/repos/aaronlehmann/distribution/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aaronlehmann/distribution/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aaronlehmann/distribution/teams","hooks_url":"https://api.github.com/repos/aaronlehmann/distribution/hooks","issue_events_url":"https://api.github.com/repos/aaronlehmann/distribution/issues/events{/number}","events_url":"https://api.github.com/repos/aaronlehmann/distribution/events","assignees_url":"https://api.github.com/repos/aaronlehmann/distribution/assignees{/user}","branches_url":"https://api.github.com/repos/aaronlehmann/distribution/branches{/branch}","tags_url":"https://api.github.com/repos/aaronlehmann/distribution/tags","blobs_url":"https://api.github.com/repos/aaronlehmann/distribution/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aaronlehmann/distribution/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aaronlehmann/distribution/git/refs{/sha}","trees_url":"https://api.github.com/repos/aaronlehmann/distribution/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aaronlehmann/distribution/statuses/{sha}","languages_url":"https://api.github.com/repos/aaronlehmann/distribution/languages","stargazers_url":"https://api.github.com/repos/aaronlehmann/distribution/stargazers","contributors_url":"https://api.github.com/repos/aaronlehmann/distribution/contributors","subscribers_url":"https://api.github.com/repos/aaronlehmann/distribution/subscribers","subscription_url":"https://api.github.com/repos/aaronlehmann/distribution/subscription","commits_url":"https://api.github.com/repos/aaronlehmann/distribution/commits{/sha}","git_commits_url":"https://api.github.com/repos/aaronlehmann/distribution/git/commits{/sha}","comments_url":"https://api.github.com/repos/aaronlehmann/distribution/comments{/number}","issue_comment_url":"https://api.github.com/repos/aaronlehmann/distribution/issues/comments{/number}","contents_url":"https://api.github.com/repos/aaronlehmann/distribution/contents/{+path}","compare_url":"https://api.github.com/repos/aaronlehmann/distribution/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aaronlehmann/distribution/merges","archive_url":"https://api.github.com/repos/aaronlehmann/distribution/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aaronlehmann/distribution/downloads","issues_url":"https://api.github.com/repos/aaronlehmann/distribution/issues{/number}","pulls_url":"https://api.github.com/repos/aaronlehmann/distribution/pulls{/number}","milestones_url":"https://api.github.com/repos/aaronlehmann/distribution/milestones{/number}","notifications_url":"https://api.github.com/repos/aaronlehmann/distribution/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aaronlehmann/distribution/labels{/name}","releases_url":"https://api.github.com/repos/aaronlehmann/distribution/releases{/id}","created_at":"2015-07-07T23:02:33Z","updated_at":"2015-07-07T23:02:34Z","pushed_at":"2015-07-31T00:08:15Z","git_url":"git://github.com/aaronlehmann/distribution.git","ssh_url":"git@github.com:aaronlehmann/distribution.git","clone_url":"https://github.com/aaronlehmann/distribution.git","svn_url":"https://github.com/aaronlehmann/distribution","homepage":null,"size":3204,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"e83345626608aa943d5c8a027fddcf54814d9545","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":28366058,"name":"distribution","full_name":"docker/distribution","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/distribution","description":"The Docker toolset to pack, ship, store, and deliver content","fork":false,"url":"https://api.github.com/repos/docker/distribution","forks_url":"https://api.github.com/repos/docker/distribution/forks","keys_url":"https://api.github.com/repos/docker/distribution/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/distribution/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/distribution/teams","hooks_url":"https://api.github.com/repos/docker/distribution/hooks","issue_events_url":"https://api.github.com/repos/docker/distribution/issues/events{/number}","events_url":"https://api.github.com/repos/docker/distribution/events","assignees_url":"https://api.github.com/repos/docker/distribution/assignees{/user}","branches_url":"https://api.github.com/repos/docker/distribution/branches{/branch}","tags_url":"https://api.github.com/repos/docker/distribution/tags","blobs_url":"https://api.github.com/repos/docker/distribution/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/distribution/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/distribution/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/distribution/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/distribution/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/distribution/languages","stargazers_url":"https://api.github.com/repos/docker/distribution/stargazers","contributors_url":"https://api.github.com/repos/docker/distribution/contributors","subscribers_url":"https://api.github.com/repos/docker/distribution/subscribers","subscription_url":"https://api.github.com/repos/docker/distribution/subscription","commits_url":"https://api.github.com/repos/docker/distribution/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/distribution/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/distribution/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/distribution/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/distribution/contents/{+path}","compare_url":"https://api.github.com/repos/docker/distribution/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/distribution/merges","archive_url":"https://api.github.com/repos/docker/distribution/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/distribution/downloads","issues_url":"https://api.github.com/repos/docker/distribution/issues{/number}","pulls_url":"https://api.github.com/repos/docker/distribution/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/distribution/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/distribution/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/distribution/labels{/name}","releases_url":"https://api.github.com/repos/docker/distribution/releases{/id}","created_at":"2014-12-22T23:49:26Z","updated_at":"2015-07-30T20:35:09Z","pushed_at":"2015-07-31T00:20:14Z","git_url":"git://github.com/docker/distribution.git","ssh_url":"git@github.com:docker/distribution.git","clone_url":"https://github.com/docker/distribution.git","svn_url":"https://github.com/docker/distribution","homepage":null,"size":12369,"stargazers_count":793,"watchers_count":793,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":307,"mirror_url":null,"open_issues_count":108,"forks":307,"open_issues":108,"watchers":793,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/distribution/pulls/763"},"html":{"href":"https://github.com/docker/distribution/pull/763"},"issue":{"href":"https://api.github.com/repos/docker/distribution/issues/763"},"comments":{"href":"https://api.github.com/repos/docker/distribution/issues/763/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/distribution/pulls/763/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/distribution/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/distribution/pulls/763/commits"},"statuses":{"href":"https://api.github.com/repos/docker/distribution/statuses/764c2ae6f56ec839d0d3164d9750fc3e6038071c"}}}}