# 上下文截止时间已超过

- **ID:** `go/context-deadline-exceeded-in-goroutine`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用带截止时间的上下文的 goroutine 未在规定时间内完成，派生上下文返回 DeadlineExceeded。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.7+ | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   for {
    select {
    case <-ctx.Done():
        return ctx.Err()
    default:
        doChunk()
    }
}
   ```
2. **** (92% 成功率)
   ```
   ctx, cancel := context.WithCancel(parent)
defer cancel()
   ```

## 无效尝试

- **** — Hides the underlying slowness; the deadline will eventually be hit again. (80% 失败率)
- **** — Downstream operations see a cancelled context and fail with different errors. (85% 失败率)
