{
  "id": "python/aiohttp-client-connector-timeout",
  "signature": "asyncio.exceptions.TimeoutError: Connection timeout to host",
  "signature_zh": "asyncio 异常：连接主机超时",
  "regex": "asyncio\\.exceptions\\.TimeoutError:\\ Connection\\ timeout\\ to\\ host",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The TCP connection to the remote host takes longer than the specified timeout, often due to network issues or server overload.",
  "root_cause_type": "generic",
  "root_cause_zh": "与远程主机的 TCP 连接耗时超过指定的超时时间，通常是由于网络问题或服务器过载。",
  "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": "Increasing timeout to a very high value",
      "why_fails": "This masks the underlying issue and may cause the application to hang indefinitely.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    },
    {
      "action": "Retrying immediately without backoff",
      "why_fails": "If the server is overloaded, immediate retries may worsen the situation and still timeout.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Implement exponential backoff retry logic",
      "success_rate": 0.85,
      "how": "import asyncio\nasync def fetch_with_retry(url, max_retries=3):\n    for i in range(max_retries):\n        try:\n            async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as resp:\n                return await resp.text()\n        except asyncio.TimeoutError:\n            await asyncio.sleep(2**i)\n    raise",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a custom connector with adjusted timeouts",
      "success_rate": 0.8,
      "how": "connector = aiohttp.TCPConnector(limit=10, force_close=True)\ntimeout = aiohttp.ClientTimeout(total=30, connect=10)\nasync with aiohttp.ClientSession(connector=connector, timeout=timeout) as session:",
      "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-09-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}