{"record":{"id":"e36a70cd0709a4a2","repo":"hashicorp/terraform","slug":"unexpected-http-response-code-d","errorCode":null,"errorMessage":"Unexpected HTTP response code %d","messagePattern":"Unexpected HTTP response code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/http/client.go","lineNumber":122,"sourceCode":"\t\tbody, err := io.ReadAll(resp.Body)\n\t\tif err != nil {\n\t\t\treturn \"\", &statemgr.LockError{\n\t\t\t\tErr: fmt.Errorf(\"HTTP remote state already locked, failed to read body\"),\n\t\t\t}\n\t\t}\n\t\texisting := statemgr.LockInfo{}\n\t\terr = json.Unmarshal(body, &existing)\n\t\tif err != nil {\n\t\t\treturn \"\", &statemgr.LockError{\n\t\t\t\tErr: fmt.Errorf(\"HTTP remote state already locked, failed to unmarshal body\"),\n\t\t\t}\n\t\t}\n\t\treturn \"\", &statemgr.LockError{\n\t\t\tInfo: &existing,\n\t\t\tErr:  fmt.Errorf(\"HTTP remote state already locked: ID=%s\", existing.ID),\n\t\t}\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"Unexpected HTTP response code %d\", resp.StatusCode)\n\t}\n}\n\nfunc (c *httpClient) Unlock(id string) error {\n\tif c.UnlockURL == nil {\n\t\treturn nil\n\t}\n\n\tresp, err := c.httpRequest(c.UnlockMethod, c.UnlockURL, &c.jsonLockInfo, \"unlock\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()\n\n\tswitch resp.StatusCode {\n\tcase http.StatusOK:\n\t\treturn nil\n\tdefault:","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/http/client.go#L104-L140","documentation":"Lock() received a status code outside the handled set (200/401/403/409/423). The numeric code is printed. Common culprits are 400 (malformed lock request body), 404 (lock endpoint not found), 405 (method not allowed — server rejects LOCK), or 5xx. Indicates a mismatch between the client's expectations and the server's lock API.","triggerScenarios":"lock_address points at a URL that returns 404; server does not implement the LOCK method (405); server requires a different lock request schema (400); transient 5xx during lock. Fires during lock acquisition.","commonSituations":"Wrong lock_address; server only supports a different locking protocol; reverse proxy not forwarding custom HTTP methods; server bug returning 500 on lock.","solutions":["Reproduce with `curl -i -X <lock_method> <lock_address>` to see the exact response and message.","Verify lock_address matches the server's documented lock endpoint and lock_method is one the server accepts.","If the server does not support locking, omit lock_address/unlock_address to disable locking entirely.","For 5xx, inspect server logs and retry; consider raising retry_max."],"exampleFix":"// before: server doesn't implement locking\nbackend \"http\" {\n  address       = \"https://state/state\"\n  lock_address  = \"https://state/lock\"\n  unlock_address = \"https://state/unlock\"\n}\n// after: drop locking if unsupported\nbackend \"http\" {\n  address = \"https://state/state\"\n}","handlingStrategy":"try-catch","validationCode":"// Smoke-test the lock endpoint contract in CI\nfunc probeLock(method, url, user, pass string) error {\n  req, _ := http.NewRequest(method, url, nil)\n  req.SetBasicAuth(user, pass)\n  resp, err := http.DefaultClient.Do(req)\n  if err != nil { return err }\n  defer resp.Body.Close()\n  switch {\n  case resp.StatusCode == http.StatusMethodNotAllowed:\n    return fmt.Errorf(\"server rejects %s method\", method)\n  case resp.StatusCode == http.StatusNotFound:\n    return fmt.Errorf(\"lock endpoint not found\")\n  }\n  return nil\n}","typeGuard":"func isUnexpectedLockCode(status int) bool {\n  switch status {\n  case http.StatusOK, http.StatusUnauthorized, http.StatusForbidden,\n    http.StatusConflict, http.StatusLocked:\n    return false\n  }\n  return true\n}","tryCatchPattern":null,"preventionTips":["Verify lock_address/lock_method match the server contract.","Drop lock_address/unlock_address if the server lacks locking support.","Probe the lock endpoint in CI with curl before terraform."],"tags":["locking","http","http-backend","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}