{
  "id": "python/starlette-lifespan-startup-error",
  "signature": "RuntimeError: Task exception was never retrieved\nfuture: <Task finished ...> ... Error during lifespan startup",
  "signature_zh": "RuntimeError: 任务异常未被获取\nfuture: <Task finished ...> ... lifespan 启动期间出错",
  "regex": "RuntimeError:\\ Task\\ exception\\ was\\ never\\ retrieved\\\nfuture:\\ <Task\\ finished\\ \\.\\.\\.>\\ \\.\\.\\.\\ Error\\ during\\ lifespan\\ startup",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An exception raised inside the lifespan startup handler prevents the ASGI server from fully starting.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 lifespan 启动处理程序中抛出的异常阻止了 ASGI 服务器完成启动。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Skips DB connection and other required startup logic.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Server starts in a broken state with missing resources.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "from contextlib import asynccontextmanager\n@asynccontextmanager\nasync def lifespan(app):\n    try:\n        await init_db()\n    except Exception:\n        logger.exception('startup failed')\n        raise\n    yield",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "for _ in range(5):\n    try: await init_db(); break\n    except Exception: await asyncio.sleep(2)",
      "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": "true",
  "first_seen": "2024-12-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}