{"record":{"id":"b570370c2dc11344","repo":"hashicorp/terraform","slug":"error-unlocking-alibaba-cloud-oss-state-file-loc","errorCode":null,"errorMessage":"Error unlocking Alibaba Cloud OSS state file:\n\nLock ID: %s\nError message: %#v\n\nYou may have to force-unlock this state in order to use it again.\nThe Alibaba Cloud backend acquires a lock during initialization to ensure the initial state file is created.","messagePattern":"Error unlocking Alibaba Cloud OSS state file:\n\nLock ID: (.+?)\nError message: %#v\n\nYou may have to force-unlock this state in order to use it again\\.\nThe Alibaba Cloud backend acquires a lock during initialization to ensure the initial state file is created\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend_state.go","lineNumber":157,"sourceCode":"\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 {\n\t\t\tif err := stateMgr.WriteState(states.NewState()); err != nil {\n\t\t\t\terr = lockUnlock(err)\n\t\t\t\treturn nil, diags.Append(err)\n\t\t\t}\n\t\t\tif err := stateMgr.PersistState(nil); err != nil {\n\t\t\t\terr = lockUnlock(err)","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/oss/backend_state.go#L139-L175","documentation":"Thrown by the lockUnlock helper inside StateMgr init: after acquiring the OSS state lock and then encountering an error during RefreshState/state-write, the backend tried to release the lock (stateMgr.Unlock) and that unlock itself failed. The user is told the lock ID and advised to force-unlock manually.","triggerScenarios":"Unlock(lockId) returned an error while cleaning up after a prior failure during state initialization. The OTS DeleteRow to release the lock failed — credentials, endpoint, or the lock row changed between acquire and release.","commonSituations":"Credentials rotated between lock and unlock; OTS transient failure; lock row manually removed mid-init; permission revoked mid-run. The state is now stranded behind an unreleased lock.","solutions":["Record the reported Lock ID and run 'terraform force-unlock <LOCK_ID>'.","Verify OTS credentials still have ots:DeleteRow on the lock table.","Confirm OTS endpoint reachability and retry the init.","Investigate why the original RefreshState failed to prevent repeated lock-then-fail cycles."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// If unlock fails during cleanup, report the lock ID for manual force-unlock.\nif err := stateMgr.Unlock(lockId); err != nil {\n    return fmt.Errorf(\"unlock failed; run 'terraform force-unlock %s': %w\", lockId, err)\n}","preventionTips":["Train operators to capture the lock ID from the error and run force-unlock.","Investigate recurring lock-then-fail patterns (the original RefreshState error) rather than just unlocking.","Verify OTS DeleteRow permission persists for the whole run."],"tags":["alibaba-cloud","tablestore","ots","terraform","state-lock","force-unlock","cleanup"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}