{"record":{"id":"d7517fd53d2f880a","repo":"Netflix/chaosmonkey","slug":"failed-to-close-response-body-from-s-v","errorCode":null,"errorMessage":"failed to close response body from %s: %v","messagePattern":"failed to close response body from (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spinnaker/spinnaker.go","lineNumber":355,"sourceCode":"\t\t\t\t\tdata[account].Clusters[clusterName][region][asgName][i] = D.InstanceID(instance.Name)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn D.NewApp(appName, data), nil\n}\n\n// AppNames returns list of names of all apps\nfunc (s Spinnaker) AppNames() (appnames []string, err error) {\n\turl := s.appsURL()\n\tresp, err := s.client.Get(url)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not retrieve list of apps from spinnaker url %s: %v\", url, err)\n\t}\n\n\tdefer func() {\n\t\tif cerr := resp.Body.Close(); cerr != nil && err == nil {\n\t\t\terr = fmt.Errorf(\"failed to close response body from %s: %v\", url, err)\n\t\t}\n\t}()\n\n\tbody, err := ioutil.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read body when retrieving spinnaker app names from %s: %v\", url, err)\n\t}\n\tvar apps []spinnakerApp\n\terr = json.Unmarshal(body, &apps)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not parse spinnaker apps list from %s: body: \\\"%s\\\": %v\", url, string(body), err)\n\t}\n\n\tresult := make([]string, len(apps))\n\tfor i, app := range apps {\n\t\tresult[i] = app.Name\n\t}\n","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/Netflix/chaosmonkey/blob/eaa28fb761c0ebe8644d1333e5d164e9cc3071e9/spinnaker/spinnaker.go#L337-L373","documentation":"AppNames() registers a deferred closure that closes the HTTP response body; if Body.Close() fails and no earlier error exists, the function's named return err is set to this wrapped message. It is an unusual, low-level I/O error surfaced by the defer pattern.","triggerScenarios":"Calling AppNames() where resp.Body.Close() on the Spinnaker apps response returns a non-nil error while err was still nil (i.e., all prior steps succeeded).","commonSituations":"Extremely rare in practice; can occur with certain custom http.Client transports/wrappers or connection teardown problems; typically indicates resource/transport-level trouble rather than a Spinnaker API problem.","solutions":["Retry the operation; the failure is usually transient transport teardown","Inspect the wrapped inner error (%v) to identify the transport-level cause","Check for custom HTTP transports/middlewares around the client that could affect body closing","Ensure the host is not exhausting file descriptors (ulimit -n)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"names, err := spin.AppNames()\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to close response body\") {\n\t\t// rare transport-level close failure; safe to retry\n\t\tnames, err = retryWithBackoff(3, spin.AppNames)\n\t}\n\tif err != nil { return err }\n}","preventionTips":["Avoid custom http.Transport wrappers that break body closing","Watch file-descriptor limits on the chaosmonkey host","Treat as transient and retry","Investigate the inner error if it recurs"],"tags":["http","io","defer"],"backgroundTag":"response-body-close-failed","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"}