{
  "id": "go/database-sql-rows-close-error",
  "signature": "sql: Rows are closed",
  "signature_zh": "sql: 行已关闭",
  "regex": "sql: Rows are closed",
  "domain": "go",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "Calling Scan or Next on a *sql.Rows object after it has been explicitly closed or after all rows have been exhausted without proper iteration.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 *sql.Rows 对象被显式关闭或所有行已耗尽但未正确迭代后，调用 Scan 或 Next。",
  "versions": [
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding defer rows.Close() after checking error but before iterating",
      "why_fails": "Deferring close doesn't prevent premature closure; the error occurs after rows are exhausted, not from missing close.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Calling rows.Close() multiple times",
      "why_fails": "Closing an already closed rows object is safe in Go, but doesn't fix the premature access; the root cause is logic error.",
      "fail_rate": 0.45,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure rows.Next() loop runs to completion before accessing rows: for rows.Next() { ... }; if err := rows.Err(); err != nil { ... }",
      "success_rate": 0.92,
      "how": "Ensure rows.Next() loop runs to completion before accessing rows: for rows.Next() { ... }; if err := rows.Err(); err != nil { ... }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Avoid calling rows.Close() before finishing iteration; let defer handle it after the loop.",
      "success_rate": 0.85,
      "how": "Avoid calling rows.Close() before finishing iteration; let defer handle it after the loop.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保 rows.Next() 循环完整执行后再访问行：for rows.Next() { ... }; if err := rows.Err(); err != nil { ... }",
    "避免在迭代完成前调用 rows.Close()；让 defer 在循环后处理。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/database/sql#Rows",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}