{"record":{"id":"4a3276aa87d56273","repo":"hashicorp/terraform","slug":"unable-to-read-content-from-response-w","errorCode":null,"errorMessage":"unable to read 'content' from response: %w","messagePattern":"unable to read 'content' from response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oci/client.go","lineNumber":107,"sourceCode":"\t\tgetRequest.OpcSseCustomerKeySha256 = common.String(c.SSECustomerKeySHA256)\n\t\tgetRequest.OpcSseCustomerAlgorithm = common.String(c.SSECustomerAlgorithm)\n\t}\n\t// Get object from OCI\n\tgetResponse, err := c.objectStorageClient.GetObject(ctx, getRequest)\n\tif err != nil {\n\t\tvar ociErr common.ServiceError\n\t\tif errors.As(err, &ociErr) {\n\t\t\treturn 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())\n\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to access object '%s' in bucket '%s': %w\", c.path, c.bucketName, err)\n\t}\n\tdefer getResponse.Content.Close()\n\n\t// Read object content\n\tcontentArray, err := io.ReadAll(getResponse.Content)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to read 'content' from response: %w\", err)\n\t}\n\n\t// Compute MD5 hash\n\tmd5Hash := getResponse.ContentMd5\n\tif md5Hash == nil || len(*md5Hash) == 0 {\n\t\tmd5Hash = getResponse.OpcMultipartMd5\n\t}\n\t// Construct payload\n\tpayload := &remote.Payload{\n\t\tData: contentArray,\n\t\tMD5:  []byte(*md5Hash),\n\t}\n\n\t// Return an error instead of `nil, nil` if the object is empty\n\tif len(payload.Data) == 0 {\n\t\treturn nil, fmt.Errorf(\"object %q is empty\", c.path)\n\t}\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oci/client.go#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check errors.Is(err, context.Canceled)/context.DeadlineExceeded to distinguish a user-driven cancel from a network reset.","Re-run the operation; transient mid-stream resets usually succeed on retry thanks to the body being freshly re-fetched.","If the state file is very large, reduce concurrent state readers and ensure the host has stable bandwidth to the object storage endpoint.","If persistent, capture a tcpdump of the object storage connection to confirm truncation/reset by an intermediary (NAT/proxy)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Bound the read with a context-aware reader and check ctx before reading:\nif ctx.Err() != nil { return ctx.Err() }\n// Optionally cap the body size to state expectations to fail fast on a huge/corrupt object.","typeGuard":"// Distinguish cancel vs reset:\nif errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n    // user/timeout driven\n} else if errors.Is(err, io.ErrUnexpectedEOF) {\n    // server closed before full body\n}","tryCatchPattern":"contentArray, err := io.ReadAll(getResponse.Content)\nif err != nil {\n    return nil, fmt.Errorf(\"unable to read 'content' from response: %w\", err)\n}","preventionTips":["Avoid interrupting Terraform during a large state download.","Ensure stable bandwidth; mid-stream resets are the main cause.","Retry on transient resets; they usually clear immediately."],"tags":["oci","object-storage","stream","io","network","context","terraform-state"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}