{"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":"error_code","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/oci/client.go#L298-L334","documentation":"The lock-file GetObject succeeded but io.ReadAll failed while reading its (small) body. The stream was interrupted between headers and the full body read.","triggerScenarios":"Connection dropped mid-read of the lock file; server reset the stream; client context cancelled during the read.","commonSituations":"Flaky network during unlock; CI runner under heavy load dropping idle connections; aggressive read timeout.","solutions":["Retry the Unlock — the lock file content has not changed, only the stream broke.","Stabilize the network path; lock files are small, so chronic failures indicate a connectivity issue.","If retries keep failing, inspect the lock object directly in the bucket to confirm it is intact."],"exampleFix":"// before: single Unlock attempt that dies on a network blip\nreturn client.Unlock(id)\n// after: retry on read-content failures\nfor i := 0; i < 3; i++ {\n    err := client.Unlock(id)\n    if err == nil { return nil }\n    if strings.Contains(err.Error(), \"failed to read existing lock file content\") {\n        time.Sleep(backoff(i)); continue\n    }\n    return err\n}\nreturn err","handlingStrategy":"retry","validationCode":null,"typeGuard":"func isLockReadErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to read existing lock file content\")\n}","tryCatchPattern":"// Retry unlock on transient body-read failures\nfor i := 0; i < 3; i++ {\n    err := c.Unlock(id)\n    if err == nil || !isLockReadErr(err) { return err }\n    time.Sleep(backoff(i))\n}","preventionTips":["Lock files are tiny — chronic read failures indicate a real network issue; fix that first.","Stabilize the network path before retrying to avoid burning attempts.","Log the underlying io.ReadAll error for diagnosis.","Avoid concurrent unlocks that delete the lock mid-read."],"tags":["oci","state-locking","io","network"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}