# HTTP 504 截止时间超时：等待 Cloud Run 容器启动时上游请求超时 60 秒

- **ID:** `cloud/gcp-cloud-run-cold-start-http-timeout`
- **领域:** cloud
- **类别:** runtime_error
- **错误码:** `504`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Cloud Run 冷启动延迟超过了 60 秒的 HTTP 负载均衡器超时，原因是容器镜像过大或应用程序初始化缓慢。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Cloud Run managed platform (gcloud CLI 450.0.0) | active | — | — |
| Cloud Run for Anthos 1.28 | active | — | — |
| Google Cloud SDK 450.0.0 | active | — | — |

## 解决方案

1. ```
   Reduce container image size by using a slim base image (e.g., 'alpine' instead of 'ubuntu') and removing build dependencies. For Node.js apps, run 'npm prune --production' before building the image.
   ```
2. ```
   Enable min-instances for Cloud Run to keep at least one instance warm: 'gcloud run services update SERVICE --min-instances=1'. This eliminates cold starts for most requests.
   ```

## 无效尝试

- **** — Larger resources do not reduce cold start time; they only affect runtime performance. Cold start is dominated by image download and app startup. (95% 失败率)
- **** — Startup CPU boost only helps during the startup probe period, not the initial HTTP request timeout. The 504 occurs before the probe even begins. (80% 失败率)
