{"record":{"id":"3cf40f658fbd5e72","repo":"hashicorp/terraform","slug":"failed-to-read-existing-lock-file-content-w","errorCode":null,"errorMessage":"failed to read existing lock file content: %w","messagePattern":"failed to read existing lock file content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oci/client.go","lineNumber":316,"sourceCode":"// getLockInfo retrieves and parses a lock file from an oci bucket.\nfunc (c *RemoteClient) getLockInfo(ctx context.Context) (*statemgr.LockInfo, string, error) {\n\t// Attempt to retrieve the lock file from\n\tgetRequest := objectstorage.GetObjectRequest{\n\t\tNamespaceName: common.String(c.namespace),\n\t\tObjectName:    common.String(c.lockFilePath),\n\t\tBucketName:    common.String(c.bucketName),\n\t\tRequestMetadata: common.RequestMetadata{\n\t\t\tRetryPolicy: getDefaultRetryPolicy(),\n\t\t},\n\t}\n\n\tgetResponse, err := c.objectStorageClient.GetObject(ctx, getRequest)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"failed to get existing lock file: %w\", err)\n\t}\n\tlockByteData, err := io.ReadAll(getResponse.Content)\n\tif err != nil {\n\t\treturn nil, *getResponse.ETag, fmt.Errorf(\"failed to read existing lock file content: %w\", err)\n\t}\n\tlockInfo := &statemgr.LockInfo{}\n\tif err := json.Unmarshal(lockByteData, lockInfo); err != nil {\n\t\treturn lockInfo, \"\", fmt.Errorf(\"failed to unmarshal JSON data into LockInfo struct: %w\", err)\n\t}\n\treturn lockInfo, *getResponse.ETag, nil\n}\nfunc (c *RemoteClient) Unlock(id string) error {\n\tctx := context.TODO()\n\tlogger := logWithOperation(\"unlock-state-file\").Named(c.lockFilePath)\n\tlogger.Info(\"unlocking remote state\")\n\tlockInfo, etag, err := c.getLockInfo(ctx)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to retrieve lock information from OCI Object Storage: %w\", err)\n\t}\n\t// Verify that the provided lock ID matches the lock ID of the retrieved lock file.\n\tif lockInfo.ID != id {","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oci/client.go#L298-L334","documentation":"Raised in getLockInfo after GetObject for the lock file succeeded but io.ReadAll(getResponse.Content) failed while reading the lock file body. It is the lock-file analogue of error 303: the HTTP call worked, the body stream did not. The ETag is still captured (316 dereferences *getResponse.ETag) for caller use.","triggerScenarios":"io.ReadAll on getResponse.Content (client.go:314) returns an error: connection reset mid-stream, io.ErrUnexpectedEOF, or context cancellation while draining the (typically tiny) lock file body.","commonSituations":"Network reset while reading the lock file; context cancelled during Unlock/Lock; proxy truncating a small response. Rare for such a small object but possible on an unstable link.","solutions":["Check errors.Is for context.Canceled vs an io/net reset to distinguish user action from network.","Re-run Unlock/Lock; lock files are small and the retry usually succeeds.","If persistent, inspect the network path to object storage (proxy/NAT resetting connections)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if ctx.Err() != nil { return nil, \"\", ctx.Err() } // do not read body on a cancelled ctx","typeGuard":"if errors.Is(err, context.Canceled) || errors.Is(err, io.ErrUnexpectedEOF) { /* classify */ }","tryCatchPattern":"lockByteData, err := io.ReadAll(getResponse.Content)\nif err != nil {\n    return nil, *getResponse.ETag, fmt.Errorf(\"failed to read existing lock file content: %w\", err)\n}","preventionTips":["Keep connectivity stable for the (tiny) lock file read.","Retry transient resets.","Avoid cancelling the context during Unlock."],"tags":["oci","object-storage","stream","io","locking","network","terraform-state"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}