Netflix/chaosmonkey · warning

failed to close response body from %s: %v

Error message

failed to close response body from %s: %v

What it means

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.

Source

Thrown at spinnaker/spinnaker.go:355

					data[account].Clusters[clusterName][region][asgName][i] = D.InstanceID(instance.Name)
				}
			}
		}
	}
	return D.NewApp(appName, data), nil
}

// AppNames returns list of names of all apps
func (s Spinnaker) AppNames() (appnames []string, err error) {
	url := s.appsURL()
	resp, err := s.client.Get(url)
	if err != nil {
		return nil, fmt.Errorf("could not retrieve list of apps from spinnaker url %s: %v", url, err)
	}

	defer func() {
		if cerr := resp.Body.Close(); cerr != nil && err == nil {
			err = fmt.Errorf("failed to close response body from %s: %v", url, err)
		}
	}()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("failed to read body when retrieving spinnaker app names from %s: %v", url, err)
	}
	var apps []spinnakerApp
	err = json.Unmarshal(body, &apps)
	if err != nil {
		return nil, fmt.Errorf("could not parse spinnaker apps list from %s: body: \"%s\": %v", url, string(body), err)
	}

	result := make([]string, len(apps))
	for i, app := range apps {
		result[i] = app.Name
	}

View on GitHub (pinned to eaa28fb761)

Solutions

  1. Retry the operation; the failure is usually transient transport teardown
  2. Inspect the wrapped inner error (%v) to identify the transport-level cause
  3. Check for custom HTTP transports/middlewares around the client that could affect body closing
  4. Ensure the host is not exhausting file descriptors (ulimit -n)
Defensive patterns

Strategy: retry

Try / catch

names, err := spin.AppNames()
if err != nil {
	if strings.Contains(err.Error(), "failed to close response body") {
		// rare transport-level close failure; safe to retry
		names, err = retryWithBackoff(3, spin.AppNames)
	}
	if err != nil { return err }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of Netflix/chaosmonkey@eaa28fb761 (2026-09-03). Data as JSON: /api/errors/d7517fd53d2f880a. Report an issue: GitHub.