{
  "id": "python/starlette-asgi-lifespan-error",
  "signature": "RuntimeError: Lifespan protocol error: received 'lifespan.shutdown' before 'lifespan.startup.complete'",
  "signature_zh": "运行时错误：生命周期协议错误：在'lifespan.startup.complete'之前收到了'lifespan.shutdown'",
  "regex": "RuntimeError:\\ Lifespan\\ protocol\\ error:\\ received\\ 'lifespan\\.shutdown'\\ before\\ 'lifespan\\.startup\\.complete'",
  "domain": "python",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "The ASGI server sent a shutdown signal before the startup completed, often due to an error in the startup handler.",
  "root_cause_type": "generic",
  "root_cause_zh": "ASGI服务器在启动完成前发送了关闭信号，通常是由于启动处理器中出现错误。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring the error and restarting the server",
      "why_fails": "Error will recur if the startup handler still fails.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing the lifespan handler entirely",
      "why_fails": "Removes startup/shutdown functionality, but may hide important initialization.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Fix the error in the startup handler",
      "success_rate": 0.9,
      "how": "@app.on_event('startup')\nasync def startup():\n    try:\n        # initialization code\n    except Exception as e:\n        print(f\"Startup error: {e}\")",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use try-except in lifespan context manager",
      "success_rate": 0.85,
      "how": "@asynccontextmanager\nasync def lifespan(app):\n    try:\n        await startup()\n        yield\n    finally:\n        await shutdown()",
      "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-09-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}