hashicorp/terraform · error

unable to read 'content' from response: %w

Error message

unable to read 'content' from response: %w

What it means

Raised in getObject after GetObject returned a 200 and an open response body, but io.ReadAll(getResponse.Content) failed while streaming the object bytes. The HTTP call itself succeeded; the body read did not, so the state payload could not be materialized into memory. The defer getResponse.Content.Close() at client.go:102 still runs.

Source

Thrown at internal/backend/remote-state/oci/client.go:107

		getRequest.OpcSseCustomerKeySha256 = common.String(c.SSECustomerKeySHA256)
		getRequest.OpcSseCustomerAlgorithm = common.String(c.SSECustomerAlgorithm)
	}
	// Get object from OCI
	getResponse, err := c.objectStorageClient.GetObject(ctx, getRequest)
	if err != nil {
		var ociErr common.ServiceError
		if errors.As(err, &ociErr) {
			return nil, fmt.Errorf("failed to access object HttpStatusCode: %d\nOpcRequestId: %s\n message: %s\n ErrorCode: %s", ociErr.GetHTTPStatusCode(), ociErr.GetOpcRequestID(), ociErr.GetMessage(), ociErr.GetCode())

		}
		return nil, fmt.Errorf("failed to access object '%s' in bucket '%s': %w", c.path, c.bucketName, err)
	}
	defer getResponse.Content.Close()

	// Read object content
	contentArray, err := io.ReadAll(getResponse.Content)
	if err != nil {
		return nil, fmt.Errorf("unable to read 'content' from response: %w", err)
	}

	// Compute MD5 hash
	md5Hash := getResponse.ContentMd5
	if md5Hash == nil || len(*md5Hash) == 0 {
		md5Hash = getResponse.OpcMultipartMd5
	}
	// Construct payload
	payload := &remote.Payload{
		Data: contentArray,
		MD5:  []byte(*md5Hash),
	}

	// Return an error instead of `nil, nil` if the object is empty
	if len(payload.Data) == 0 {
		return nil, fmt.Errorf("object %q is empty", c.path)
	}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Check errors.Is(err, context.Canceled)/context.DeadlineExceeded to distinguish a user-driven cancel from a network reset.
  2. Re-run the operation; transient mid-stream resets usually succeed on retry thanks to the body being freshly re-fetched.
  3. If the state file is very large, reduce concurrent state readers and ensure the host has stable bandwidth to the object storage endpoint.
  4. If persistent, capture a tcpdump of the object storage connection to confirm truncation/reset by an intermediary (NAT/proxy).
Defensive patterns

Strategy: retry

Validate before calling

// Bound the read with a context-aware reader and check ctx before reading:
if ctx.Err() != nil { return ctx.Err() }
// Optionally cap the body size to state expectations to fail fast on a huge/corrupt object.

Type guard

// Distinguish cancel vs reset:
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
    // user/timeout driven
} else if errors.Is(err, io.ErrUnexpectedEOF) {
    // server closed before full body
}

Try / catch

contentArray, err := io.ReadAll(getResponse.Content)
if err != nil {
    return nil, fmt.Errorf("unable to read 'content' from response: %w", err)
}

Prevention

When it happens

Trigger: io.ReadAll on getResponse.Content (client.go:105) returns an error: the connection was reset mid-stream, the server sent an incomplete body, the reader returned io.ErrUnexpectedEOF, or the context was cancelled while the body was still draining.

Common situations: Reading a large state file over an unstable link; the OCI load balancer closed the keep-alive connection before the full body transferred; memory pressure causing slow reads that hit an upstream timeout; interrupted Terraform run cancelling the context during body download.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/4a3276aa87d56273. Report an issue: GitHub.