{
  "id": "python/starlette-websocket-disconnect-not-handled",
  "signature": "starlette.websockets.WebSocketDisconnect: 1000",
  "signature_zh": "Starlette WebSocket断开异常",
  "regex": "starlette\\.websockets\\.WebSocketDisconnect:\\ 1000",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "Client disconnects from a WebSocket connection, and the server code doesn't catch the `WebSocketDisconnect` exception, causing an unhandled error.",
  "root_cause_type": "generic",
  "root_cause_zh": "客户端断开WebSocket连接，服务器代码未捕获`WebSocketDisconnect`异常，导致未处理的错误。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Ignoring the exception and continuing to send messages after disconnect leads to `RuntimeError` or broken pipe errors.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Reconnecting the client doesn't help; the server must handle the disconnect gracefully.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Wrap the WebSocket communication in a try-except block: `try: await websocket.receive_text() except WebSocketDisconnect: await websocket.close()`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use a context manager like `async with websocket` which automatically handles disconnects.",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}