{"record":{"id":"8bb340a8851a9f33","repo":"hashicorp/terraform","slug":"failed-to-lock-oss-state-s","errorCode":null,"errorMessage":"failed to lock OSS state: %s","messagePattern":"failed to lock OSS state: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend_state.go","lineNumber":151,"sourceCode":"\t}\n\n\tlog.Printf(\"[DEBUG] Current workspace name: %s. All workspaces:%#v\", name, existing)\n\n\texists := false\n\tfor _, s := range existing {\n\t\tif s == name {\n\t\t\texists = true\n\t\t\tbreak\n\t\t}\n\t}\n\t// We need to create the object so it's listed by States.\n\tif !exists {\n\t\t// take a lock on this state while we write it\n\t\tlockInfo := statemgr.NewLockInfo()\n\t\tlockInfo.Operation = \"init\"\n\t\tlockId, err := client.Lock(lockInfo)\n\t\tif err != nil {\n\t\t\treturn nil, diags.Append(fmt.Errorf(\"failed to lock OSS state: %s\", err))\n\t\t}\n\n\t\t// Local helper function so we can call it multiple places\n\t\tlockUnlock := func(e error) error {\n\t\t\tif err := stateMgr.Unlock(lockId); err != nil {\n\t\t\t\treturn fmt.Errorf(strings.TrimSpace(stateUnlockError), lockId, err)\n\t\t\t}\n\t\t\treturn e\n\t\t}\n\n\t\t// Grab the value\n\t\tif err := stateMgr.RefreshState(); err != nil {\n\t\t\terr = lockUnlock(err)\n\t\t\treturn nil, diags.Append(err)\n\t\t}\n\n\t\t// If we have no state, we have to create an empty state\n\t\tif v := stateMgr.State(); v == nil {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/oss/backend_state.go#L133-L169","documentation":"Thrown during StateMgr initialization when a new workspace's state object must be created: the backend takes a Tablestore lock (client.Lock) before writing the initial empty state, and that lock acquisition failed. The %s is the underlying lock error.","triggerScenarios":"client.Lock returns an error — typically the OTS PutRow for the lock record collided with an existing lock row (RowExistenceExpectation_EXPECT_NOT_FOUND failed), the OTS endpoint was unreachable, or credentials lacked PutRow permission.","commonSituations":"A previous terraform run crashed holding a lock; another user/process is concurrently initializing the same workspace; OTS table permissions missing; transient OTS unavailability.","solutions":["Run 'terraform force-unlock <LOCK_ID>' using the lock ID reported by the conflicting run.","Confirm the OTS table grants ots:PutRow, ots:GetRow, ots:DeleteRow to the credentials in use.","Coordinate to avoid concurrent 'terraform init' against the same new workspace.","Retry after confirming OTS endpoint health."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// On init of a new workspace, catch lock failure and surface the conflicting lock ID.\nlockId, err := client.Lock(lockInfo)\nif err != nil {\n    var le *statemgr.LockError\n    if errors.As(err, &le) && le.Info != nil {\n        return fmt.Errorf(\"state locked by %s (id %s); run 'terraform force-unlock %s'\",\n            le.Info.Who, le.Info.ID, le.Info.ID)\n    }\n    return err\n}","preventionTips":["Serialize 'terraform init' across teammates (one initializer per workspace).","Always force-unlock after a crashed run before re-initializing.","Confirm OTS PutRow permission during provisioning."],"tags":["alibaba-cloud","tablestore","ots","terraform","state-lock","concurrency"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}