{
  "id": "go/database-sql-tx-commit-rollback",
  "signature": "sql: transaction has already been committed or rolled back",
  "signature_zh": "sql: 事务已提交或回滚",
  "regex": "sql:\\ transaction\\ has\\ already\\ been\\ committed\\ or\\ rolled\\ back",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling Commit() or Rollback() on a transaction that has already been finalized, leading to an error.",
  "root_cause_type": "generic",
  "root_cause_zh": "对已最终确定的事务调用 Commit() 或 Rollback()，导致错误。",
  "versions": [
    {
      "version": "1.14",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Transaction state is already final; continuing may lead to data inconsistency.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Rollback will also fail because the transaction is already done.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use defer with a check: defer func() { if err := tx.Rollback(); err != sql.ErrTxDone { log.Fatal(err) } }()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Track transaction state with a boolean: committed := false; if err := tx.Commit(); err == nil { committed = true }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}