{
  "id": "go/database-sql-transaction-commit-before-rollback",
  "signature": "error: sql: transaction has already been committed or rolled back",
  "signature_zh": "错误：sql：事务已提交或回滚",
  "regex": "error:\\ sql:\\ transaction\\ has\\ already\\ been\\ committed\\ or\\ rolled\\ back",
  "domain": "go",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Attempting to commit or rollback a transaction that has already been finalized, often due to double call or logic error.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试提交或回滚已最终确定的事务，通常由于重复调用或逻辑错误。",
  "versions": [
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Calling Rollback after Commit in defer",
      "why_fails": "Defer executes after Commit, causing panic; use flag to check.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a helper function to manage transaction lifecycle",
      "success_rate": 0.95,
      "how": "func withTx(db *sql.DB, fn func(*sql.Tx) error) error {\n    tx, err := db.Begin()\n    if err != nil { return err }\n    defer tx.Rollback()\n    if err := fn(tx); err != nil { return err }\n    return tx.Commit()\n}",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-06-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}