{
  "id": "python/starlette-async-timeout-error",
  "signature": "asyncio.TimeoutError: Task timed out after 30 seconds",
  "signature_zh": "异步超时错误：任务在 30 秒后超时",
  "regex": "asyncio\\.TimeoutError:\\ Task\\ timed\\ out\\ after\\ 30\\ seconds",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Starlette 中的异步任务执行时间超过了设定的超时限制",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette 中的异步任务执行时间超过了设定的超时限制",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "移除超时设置而不优化代码",
      "why_fails": "可能导致请求无限挂起",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "增加超时时间到很大值",
      "why_fails": "掩盖了性能问题",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "优化异步任务性能",
      "success_rate": 0.85,
      "how": "async def slow_task():\n    await asyncio.sleep(10)  # 使用异步等待而非阻塞",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用 asyncio.wait_for 设置合理超时",
      "success_rate": 0.9,
      "how": "try:\n    result = await asyncio.wait_for(task(), timeout=30)\nexcept asyncio.TimeoutError:\n    return '超时', 408",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-05-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}