# DEADLINE_EXCEEDED：操作在截止时间前未能完成。gRPC 流以状态码 4 关闭

- **ID:** `cloud/gcp-pubsub-subscription-pull-ack-deadline-exceeded`
- **领域:** cloud
- **类别:** runtime_error
- **错误码:** `DEADLINE_EXCEEDED`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Pub/Sub 订阅者的确认截止时间太短，无法完成消息处理，导致 gRPC 流式拉取在多次截止时间违规后关闭。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| gcloud_cli | active | — | — |
| pubsub_api | active | — | — |
| client_library | active | — | — |

## 解决方案

1. ```
   Increase the ack deadline for the subscription: `gcloud pubsub subscriptions update my-sub --ack-deadline=600` (10 minutes). Ensure your message processing completes within this window.
   ```
2. ```
   Implement a manual ack extension loop in your subscriber: after receiving a message, call `subscriber.modifyAckDeadline(message, 60)` every 30 seconds until processing is done, then ack. Example: `from google.cloud import pubsub_v1; subscriber.modify_ack_deadline(subscription, [message.ack_id], 60)`
   ```

## 无效尝试

- **** — Adding more subscribers doesn't fix the ack deadline; each message still has the same processing time limit. (75% 失败率)
- **** — Synchronous pull has its own timeout issues and doesn't inherently increase ack deadline. (60% 失败率)
