{
  "id": "python/fastapi-websocket-disconnect-handling",
  "signature": "starlette.websockets.WebSocketDisconnect: 1000",
  "signature_zh": "starlette.websockets.WebSocketDisconnect: 1000",
  "regex": "starlette\\.websockets\\.WebSocketDisconnect:\\ 1000",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "Client closed the WebSocket; the handler keeps calling receive/send without catching the disconnect, propagating the exception.",
  "root_cause_type": "generic",
  "root_cause_zh": "客户端关闭了 WebSocket；处理函数继续调用 receive/send 且未捕获断开异常，导致异常向上传播。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Loop keeps iterating after disconnect and raises again.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "WebSocketDisconnect subclasses Exception but should break the loop, not just log.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "Catch and break:\ntry:\n    while True:\n        data = await ws.receive_text()\nexcept WebSocketDisconnect:\n    pass",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Use ws.iter_text() which stops on disconnect.",
      "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-07-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}