{
  "id": "python/aiohttp-session-closed",
  "signature": "RuntimeError: Session is closed",
  "signature_zh": "RuntimeError: 会话已关闭",
  "regex": "RuntimeError:\\ Session\\ is\\ closed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An aiohttp.ClientSession was used after being closed, typically because it was created in an async with block that exited, or the session attribute was reused across requests after aclose().",
  "root_cause_type": "generic",
  "root_cause_zh": "aiohttp.ClientSession 在关闭后被使用，通常是因为其所在的 async with 块已退出，或在 aclose() 之后会话属性被跨请求复用。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The old session object is still closed; reassigning may leave background connectors attached to the closed session.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The session is closed, not slow; the request cannot even be queued.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "session = aiohttp.ClientSession()\ntry:\n    await session.get(url)\nfinally:\n    await session.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "async with aiohttp.ClientSession() as session:\n    async with session.get(url) as resp:\n        data = await resp.text()",
      "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-06-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}