Netflix/chaosmonkey · error

failed to close response body of %s: %v

Error message

failed to close response body of %s: %v

What it means

Returned from a deferred close in Spinnaker.asgs when resp.Body.Close fails after a successful GET of the server-groups URL; it only overwrites err if the request otherwise succeeded, signaling the response body could not be cleanly released.

Source

Thrown at spinnaker/spinnaker.go:441

		log.Println(url)
		log.Println(string(body))
		log.Fatalln(err)
	}

	return m
}

// asgs returns a slice of autoscaling groups associated with the given cluster
func (s Spinnaker) asgs(appName, account, clusterName string) (result []spinnakerServerGroup, err error) {
	url := s.serverGroupsURL(appName, account, clusterName)
	resp, err := s.client.Get(url)
	if err != nil {
		return nil, fmt.Errorf("failed to retrieve server groups url (%s): %v", url, err)
	}

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

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("failed to read body of server groups url (%s): body: '%s': %v", url, string(body), err)
	}

	// Example:
	/*
		[
		  {
		    "name": "abc-prod-v016",
		    "region": "us-east-1",
		    "zones": [
		      "us-east-1c",
		      "us-east-1d",
		      "us-east-1e"

View on GitHub (pinned to eaa28fb761)

Solutions

  1. Treat the close error as non-fatal: log it instead of replacing the already-obtained result
  2. Check whether the body was fully consumed before closing; unconsumed bodies cause close failures
  3. Reuse HTTP connections via keep-alive so close/return-to-pool errors surface early
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at spinnaker/spinnaker.go:441 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/105d103cd223fc1a. Report an issue: GitHub.