{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/comments/91745552","pull_request_review_id":12256266,"id":91745552,"diff_hunk":"@@ -634,8 +648,23 @@ func (s *Store) retryRequest(ctx context.Context, client *http.Client, reqOption\n \t\tif shouldRetryHttpResponse(attempt, resp) {\n \t\t\tresp.Body.Close()\n \t\t\tcontinue\n+\t\t} else {\n+\t\t\tstatus := (resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusCreated)\n+\t\t\t// always decode on success; decode failures only if body is not empty\n+\t\t\tif status || resp.ContentLength > 0 {\n+\t\t\t\terr = decode(status, resp)\n+\t\t\t\tresp.Body.Close()","path":"store/store.go","position":34,"original_position":34,"commit_id":"8896ef3be1229c786307ef90359f7eb624fd4f1c","original_commit_id":"8896ef3be1229c786307ef90359f7eb624fd4f1c","user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"body":"We need to _always_ close `resp.Body`. I suggest organizing it as:\r\n```\r\nif !ok && resp.ContentLength == 0 {\r\n        // do not decode on empty errors.\r\n        resp.Body.Close()\r\n        break\r\n}\r\n\r\nerr = decode(ok, resp)\r\nresp.Body.Close()\r\n...\r\n","created_at":"2016-12-09T16:16:35Z","updated_at":"2016-12-09T16:24:47Z","html_url":"https://github.com/snapcore/snapd/pull/2425#discussion_r91745552","pull_request_url":"https://api.github.com/repos/snapcore/snapd/pulls/2425","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments/91745552"},"html":{"href":"https://github.com/snapcore/snapd/pull/2425#discussion_r91745552"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2425"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/2425","id":96909441,"html_url":"https://github.com/snapcore/snapd/pull/2425","diff_url":"https://github.com/snapcore/snapd/pull/2425.diff","patch_url":"https://github.com/snapcore/snapd/pull/2425.patch","issue_url":"https://api.github.com/repos/snapcore/snapd/issues/2425","number":2425,"state":"open","locked":false,"title":"store: decode response.Body json inside retry loops","user":{"login":"stolowski","id":168604,"avatar_url":"https://avatars.githubusercontent.com/u/168604?v=3","gravatar_id":"","url":"https://api.github.com/users/stolowski","html_url":"https://github.com/stolowski","followers_url":"https://api.github.com/users/stolowski/followers","following_url":"https://api.github.com/users/stolowski/following{/other_user}","gists_url":"https://api.github.com/users/stolowski/gists{/gist_id}","starred_url":"https://api.github.com/users/stolowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stolowski/subscriptions","organizations_url":"https://api.github.com/users/stolowski/orgs","repos_url":"https://api.github.com/users/stolowski/repos","events_url":"https://api.github.com/users/stolowski/events{/privacy}","received_events_url":"https://api.github.com/users/stolowski/received_events","type":"User","site_admin":false},"body":"Decode resp.Body inside retry loop as EOF can happen on Decode too. This change required quite some refactoring in the form of decodeStrategy.\r\nIt doesn't cover Assertion call which is a bit special wrt de-serializing - it will be covered in a separate PR with a specialized retry-loop.","created_at":"2016-12-07T11:54:19Z","updated_at":"2016-12-09T16:24:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0dc83dba7426b9ab7b8ced363bbc303078a4fa0a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapd/pulls/2425/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapd/pulls/2425/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapd/issues/2425/comments","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/8896ef3be1229c786307ef90359f7eb624fd4f1c","head":{"label":"stolowski:retry-bdy","ref":"retry-bdy","sha":"8896ef3be1229c786307ef90359f7eb624fd4f1c","user":{"login":"stolowski","id":168604,"avatar_url":"https://avatars.githubusercontent.com/u/168604?v=3","gravatar_id":"","url":"https://api.github.com/users/stolowski","html_url":"https://github.com/stolowski","followers_url":"https://api.github.com/users/stolowski/followers","following_url":"https://api.github.com/users/stolowski/following{/other_user}","gists_url":"https://api.github.com/users/stolowski/gists{/gist_id}","starred_url":"https://api.github.com/users/stolowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stolowski/subscriptions","organizations_url":"https://api.github.com/users/stolowski/orgs","repos_url":"https://api.github.com/users/stolowski/repos","events_url":"https://api.github.com/users/stolowski/events{/privacy}","received_events_url":"https://api.github.com/users/stolowski/received_events","type":"User","site_admin":false},"repo":{"id":66472850,"name":"snapd","full_name":"stolowski/snapd","owner":{"login":"stolowski","id":168604,"avatar_url":"https://avatars.githubusercontent.com/u/168604?v=3","gravatar_id":"","url":"https://api.github.com/users/stolowski","html_url":"https://github.com/stolowski","followers_url":"https://api.github.com/users/stolowski/followers","following_url":"https://api.github.com/users/stolowski/following{/other_user}","gists_url":"https://api.github.com/users/stolowski/gists{/gist_id}","starred_url":"https://api.github.com/users/stolowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stolowski/subscriptions","organizations_url":"https://api.github.com/users/stolowski/orgs","repos_url":"https://api.github.com/users/stolowski/repos","events_url":"https://api.github.com/users/stolowski/events{/privacy}","received_events_url":"https://api.github.com/users/stolowski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stolowski/snapd","description":"The snapd and snap tools enable systems to work with .snap files.","fork":true,"url":"https://api.github.com/repos/stolowski/snapd","forks_url":"https://api.github.com/repos/stolowski/snapd/forks","keys_url":"https://api.github.com/repos/stolowski/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stolowski/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stolowski/snapd/teams","hooks_url":"https://api.github.com/repos/stolowski/snapd/hooks","issue_events_url":"https://api.github.com/repos/stolowski/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/stolowski/snapd/events","assignees_url":"https://api.github.com/repos/stolowski/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/stolowski/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/stolowski/snapd/tags","blobs_url":"https://api.github.com/repos/stolowski/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stolowski/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stolowski/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/stolowski/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stolowski/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/stolowski/snapd/languages","stargazers_url":"https://api.github.com/repos/stolowski/snapd/stargazers","contributors_url":"https://api.github.com/repos/stolowski/snapd/contributors","subscribers_url":"https://api.github.com/repos/stolowski/snapd/subscribers","subscription_url":"https://api.github.com/repos/stolowski/snapd/subscription","commits_url":"https://api.github.com/repos/stolowski/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/stolowski/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/stolowski/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/stolowski/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/stolowski/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/stolowski/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stolowski/snapd/merges","archive_url":"https://api.github.com/repos/stolowski/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stolowski/snapd/downloads","issues_url":"https://api.github.com/repos/stolowski/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/stolowski/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/stolowski/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/stolowski/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stolowski/snapd/labels{/name}","releases_url":"https://api.github.com/repos/stolowski/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/stolowski/snapd/deployments","created_at":"2016-08-24T14:50:18Z","updated_at":"2016-08-24T14:50:21Z","pushed_at":"2016-12-09T14:02:17Z","git_url":"git://github.com/stolowski/snapd.git","ssh_url":"git@github.com:stolowski/snapd.git","clone_url":"https://github.com/stolowski/snapd.git","svn_url":"https://github.com/stolowski/snapd","homepage":"","size":41120,"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":"snapcore:master","ref":"master","sha":"80dcb6e683931da278a47f9f26815ce34a0c8fc8","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snapd","full_name":"snapcore/snapd","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapd","description":"The snapd and snap tools enable systems to work with .snap files.","fork":false,"url":"https://api.github.com/repos/snapcore/snapd","forks_url":"https://api.github.com/repos/snapcore/snapd/forks","keys_url":"https://api.github.com/repos/snapcore/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapd/teams","hooks_url":"https://api.github.com/repos/snapcore/snapd/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapd/events","assignees_url":"https://api.github.com/repos/snapcore/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapd/tags","blobs_url":"https://api.github.com/repos/snapcore/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapd/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapd/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapd/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapd/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapd/subscription","commits_url":"https://api.github.com/repos/snapcore/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapd/merges","archive_url":"https://api.github.com/repos/snapcore/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapd/downloads","issues_url":"https://api.github.com/repos/snapcore/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapd/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapd/deployments","created_at":"2015-10-21T11:51:46Z","updated_at":"2016-12-09T09:08:25Z","pushed_at":"2016-12-09T14:34:31Z","git_url":"git://github.com/snapcore/snapd.git","ssh_url":"git@github.com:snapcore/snapd.git","clone_url":"https://github.com/snapcore/snapd.git","svn_url":"https://github.com/snapcore/snapd","homepage":"","size":44987,"stargazers_count":454,"watchers_count":454,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":136,"mirror_url":null,"open_issues_count":50,"forks":136,"open_issues":50,"watchers":454,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2425"},"html":{"href":"https://github.com/snapcore/snapd/pull/2425"},"issue":{"href":"https://api.github.com/repos/snapcore/snapd/issues/2425"},"comments":{"href":"https://api.github.com/repos/snapcore/snapd/issues/2425/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2425/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2425/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapd/statuses/8896ef3be1229c786307ef90359f7eb624fd4f1c"}}}}
{"actor":{"display_login":"niemeyer"}}