{
  "id": "cloud/gcp-cloud-run-cold-start-memory-threshold",
  "signature": "Cloud Run: Request failed with 'memory limit exceeded' during cold start, even though memory usage is below limit",
  "signature_zh": "Cloud Run：请求在冷启动期间因 '内存限制超出' 而失败，即使内存使用低于限制",
  "regex": "Request failed with 'memory limit exceeded' during cold start",
  "domain": "cloud",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "During cold start, Cloud Run allocates memory for the container and may temporarily exceed the configured memory limit due to initialization overhead (e.g., loading libraries, connecting to databases), leading to OOM kills.",
  "root_cause_type": "generic",
  "root_cause_zh": "在冷启动期间，Cloud Run 为容器分配内存，由于初始化开销（例如加载库、连接数据库）可能会暂时超过配置的内存限制，导致 OOM 杀死。",
  "versions": [
    {
      "version": "Cloud Run (fully managed) 2023-11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gcloud CLI 460.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The issue is a transient spike; increasing limit helps but may not be cost-effective.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The spike is often due to runtime dependencies, not image size.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set a higher memory limit (e.g., 512 MiB) for the Cloud Run service, and use the --concurrency flag to limit concurrent requests during cold start. Example: gcloud run deploy myservice --memory=512Mi --concurrency=1",
      "success_rate": 0.85,
      "how": "Set a higher memory limit (e.g., 512 MiB) for the Cloud Run service, and use the --concurrency flag to limit concurrent requests during cold start. Example: gcloud run deploy myservice --memory=512Mi --concurrency=1",
      "condition": "",
      "sources": []
    },
    {
      "action": "Optimize the application's startup code to defer heavy initialization (e.g., lazy-load libraries, use connection pooling) to reduce the memory spike.",
      "success_rate": 0.75,
      "how": "Optimize the application's startup code to defer heavy initialization (e.g., lazy-load libraries, use connection pooling) to reduce the memory spike.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Enable 'CPU always allocated' to keep the container warm and avoid cold starts entirely.",
      "success_rate": 0.9,
      "how": "Enable 'CPU always allocated' to keep the container warm and avoid cold starts entirely.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "为 Cloud Run 服务设置更高的内存限制（例如 512 MiB），并使用 --concurrency 标志在冷启动期间限制并发请求。示例：gcloud run deploy myservice --memory=512Mi --concurrency=1",
    "优化应用程序的启动代码，延迟执行重型初始化（例如懒加载库、使用连接池），以减少内存峰值。",
    "启用 'CPU always allocated' 以保持容器温暖，完全避免冷启动。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cloud.google.com/run/docs/configuring/memory-limits",
  "official_doc_section": null,
  "error_code": "HTTP 503",
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.78,
  "resolvable": "partial",
  "first_seen": "2023-11-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}