{
  "id": "python/starlette-websocket-disconnect",
  "signature": "websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)",
  "signature_zh": "WebSocket连接正常关闭：收到1000 (OK)；然后发送1000 (OK)",
  "regex": "websockets\\.exceptions\\.ConnectionClosedOK:\\ received\\ 1000\\ \\(OK\\);\\ then\\ sent\\ 1000\\ \\(OK\\)",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The WebSocket connection was closed by the client or server normally.",
  "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": "Assuming it's an error and trying to reconnect indefinitely.",
      "why_fails": "Normal closure is not an error; reconnecting without reason is wasteful.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the close event and continuing to send messages.",
      "why_fails": "The connection is closed; sending messages will raise another error.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Handle the close event gracefully and clean up resources.",
      "success_rate": 0.9,
      "how": "async def websocket_endpoint(websocket):\n    await websocket.accept()\n    try:\n        while True:\n            data = await websocket.receive_text()\n            await websocket.send_text(f\"Echo: {data}\")\n    except websockets.exceptions.ConnectionClosed:\n        print('Connection closed')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement reconnection logic with exponential backoff.",
      "success_rate": 0.85,
      "how": "import asyncio\nasync def connect():\n    while True:\n        try:\n            async with websockets.connect('ws://...') as ws:\n                await ws.send('hello')\n        except websockets.exceptions.ConnectionClosed:\n            await asyncio.sleep(1)",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}