Netflix/chaosmonkey · error

failed to close response body from %s

Error message

failed to close response body from %s

What it means

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.

Source

Thrown at spinnaker/spinnaker.go:181

	} else {
		client = new(http.Client)
	}

	return Spinnaker{endpoint: endpoint, client: client, user: user}, nil
}

// AccountID returns numerical ID associated with an AWS account
func (s Spinnaker) AccountID(name string) (id string, err error) {
	url := s.accountURL(name)

	resp, err := s.client.Get(url)
	if err != nil {
		return "", errors.Wrapf(err, "could not retrieve account info for %s from spinnaker url %s", name, url)
	}

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

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", errors.Wrapf(err, "failed to read body from url %s", url)
	}

	var info struct {
		AccountID string `json:"accountId"`
		Error     string `json:"error"`
	}

	err = json.Unmarshal(body, &info)
	if err != nil {
		return "", errors.Wrapf(err, "could not parse body of %s as json, body: %s, error", url, body)
	}

View on GitHub (pinned to eaa28fb761)

Solutions

  1. Wrap cerr instead of err so the close failure reason is preserved
  2. Log the close error instead of failing the whole request
  3. Ensure the body is fully read before close so the connection can be reused
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at spinnaker/spinnaker.go:181 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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