{
  "id": "python/starlette-runtimeerror-connection-does-not-exist",
  "signature": "RuntimeError: Connection does not exist.",
  "signature_zh": "运行时错误：连接不存在。",
  "regex": "RuntimeError:\\ Connection\\ does\\ not\\ exist\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to use a WebSocket connection that has already been closed or was never established.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试使用已经关闭或从未建立的WebSocket连接。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Reusing WebSocket object after disconnect",
      "why_fails": "WebSocket connections are single-use; must accept new connections.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Assuming connection persists across requests",
      "why_fails": "Each WebSocket request creates a new connection object.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check if WebSocket is connected before using",
      "success_rate": 0.85,
      "how": "if websocket.client_state == starlette.websockets.WebSocketState.CONNECTED:\n    await websocket.send_text('hello')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Handle disconnection with try-except",
      "success_rate": 0.9,
      "how": "try:\n    await websocket.receive_text()\nexcept RuntimeError:\n    # connection closed\n    pass",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}