{
  "id": "python/starlette-websocket-timeout",
  "signature": "asyncio.TimeoutError: WebSocket receive timed out",
  "signature_zh": "异步超时错误：WebSocket接收超时",
  "regex": "asyncio\\.TimeoutError:\\ WebSocket\\ receive\\ timed\\ out",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "A WebSocket receive operation exceeds the configured timeout period.",
  "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": "Increasing timeout to an extremely high value",
      "why_fails": "May cause resource exhaustion; not a real fix.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the timeout and retrying indefinitely",
      "why_fails": "Leads to infinite loop and resource leak.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use asyncio.wait_for with a reasonable timeout",
      "success_rate": 0.9,
      "how": "try:\n    data = await asyncio.wait_for(websocket.receive_text(), timeout=10)\nexcept asyncio.TimeoutError:\n    await websocket.close(code=1000)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set timeout in the WebSocket endpoint configuration",
      "success_rate": 0.85,
      "how": "from starlette.websockets import WebSocketEndpoint\nclass MyEndpoint(WebSocketEndpoint):\n    receive_timeout = 30",
      "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-08-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}