{"record":{"id":"9506c3946cc66a8d","repo":"Netflix/chaosmonkey","slug":"failed-to-close-response-body-from-s","errorCode":null,"errorMessage":"failed to close response body from %s","messagePattern":"failed to close response body from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spinnaker/spinnaker.go","lineNumber":181,"sourceCode":"\t} else {\n\t\tclient = new(http.Client)\n\t}\n\n\treturn Spinnaker{endpoint: endpoint, client: client, user: user}, nil\n}\n\n// AccountID returns numerical ID associated with an AWS account\nfunc (s Spinnaker) AccountID(name string) (id string, err error) {\n\turl := s.accountURL(name)\n\n\tresp, err := s.client.Get(url)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"could not retrieve account info for %s from spinnaker url %s\", name, url)\n\t}\n\n\tdefer func() {\n\t\tif cerr := resp.Body.Close(); cerr != nil && err == nil {\n\t\t\terr = errors.Wrapf(err, \"failed to close response body from %s\", url)\n\t\t}\n\t}()\n\n\tbody, err := ioutil.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"failed to read body from url %s\", url)\n\t}\n\n\tvar info struct {\n\t\tAccountID string `json:\"accountId\"`\n\t\tError     string `json:\"error\"`\n\t}\n\n\terr = json.Unmarshal(body, &info)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"could not parse body of %s as json, body: %s, error\", url, body)\n\t}\n","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/Netflix/chaosmonkey/blob/eaa28fb761c0ebe8644d1333e5d164e9cc3071e9/spinnaker/spinnaker.go#L163-L199","documentation":"Returned from a deferred close in Spinnaker.AccountID when resp.Body.Close fails after a successful GET; it only replaces err if the request otherwise succeeded, indicating the response body could not be cleanly released. Note the wrap uses err (the nil named return) rather than cerr, so the close error itself is lost.","triggerScenarios":"Thrown at spinnaker/spinnaker.go:181 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap cerr instead of err so the close failure reason is preserved","Log the close error instead of failing the whole request","Ensure the body is fully read before close so the connection can be reused"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eaa28fb761c0ebe8644d1333e5d164e9cc3071e9","analyzedAt":"2026-09-03T17:04:39.020Z","contentChangedAt":"2026-09-03T17:04:39.020Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}