Skip to content

Commit 9b7e4fb

Browse files
authored
Close HTTP response bodies to fix bodyclose lint (#566)
Two spots were missing resp.Body.Close() calls: - update_test.go: the http.Post response was discarded. Now we capture it and close the body before returning. - run.go (checkCredAccess): the response from the GitHub API token-scope check was never closed. Added a defer.
1 parent fe8b225 commit 9b7e4fb

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

cmd/dependabot/internal/cmd/update_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,11 @@ func Test_extractInput(t *testing.T) {
295295
// Retry the calls in case the server takes a bit to start up.
296296
for i := 0; i < 10; i++ {
297297
body := strings.NewReader(`{"job":{"package-manager":"go_modules"}}`)
298-
_, err := http.Post("http://127.0.0.1:8080", "application/json", body)
298+
resp, err := http.Post("http://127.0.0.1:8080", "application/json", body)
299299
if err != nil {
300300
time.Sleep(10 * time.Millisecond)
301301
} else {
302+
resp.Body.Close()
302303
return
303304
}
304305
}

internal/infra/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ func checkCredAccess(ctx context.Context, job *model.Job, creds []model.Credenti
255255
if err != nil {
256256
return fmt.Errorf("failed making request: %w", err)
257257
}
258+
defer resp.Body.Close()
258259
if resp.StatusCode != http.StatusOK {
259260
return fmt.Errorf("failed request to GitHub API to check access: %s", resp.Status)
260261
}

0 commit comments

Comments
 (0)