# 容器终止：退出代码 137（内存不足）

- **ID:** `cloud/gcp-cloud-run-container-crash-oom`
- **领域:** cloud
- **类别:** resource_error
- **错误码:** `137`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Cloud Run 容器超过其分配的内存限制（默认 512 MB），导致内核 OOM 杀手终止进程。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Cloud Run (fully managed) | active | — | — |
| Cloud Run for Anthos | active | — | — |
| gcloud CLI 460.0.0 | active | — | — |

## 解决方案

1. ```
   Increase the memory limit for the Cloud Run service: `gcloud run deploy <SERVICE> --memory=1Gi --region=us-central1`. Monitor memory usage via Cloud Monitoring and adjust accordingly. Also consider reducing concurrency: `gcloud run deploy <SERVICE> --concurrency=10` to limit simultaneous requests.
   ```
2. ```
   Profile the application to find memory-heavy operations. For Node.js, use `--max-old-space-size` flag in the Dockerfile: `CMD ["node", "--max-old-space-size=256", "app.js"]`. For Python, use `gc.set_threshold()` to tune garbage collection.
   ```

## 无效尝试

- **** — Memory leaks continue to grow unbounded; the container will eventually hit the new limit too, wasting money. (85% 失败率)
- **** — The same container image with the same memory limit will crash again under the same load. (95% 失败率)
