# rpc 错误：code = Aborted desc = 并发冲突：版本不匹配

- **ID:** `go/grpc-aborted-concurrency`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

由于并发冲突（例如乐观锁失败导致资源版本更改），操作被中止。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   for {
    resource, err := client.Get(ctx, &GetRequest{Id: id})
    if err != nil { return err }
    resource.Data = newData
    _, err = client.Update(ctx, resource)
    if status.Code(err) != codes.Aborted {
        return err
    }
    // retry
}
   ```
2. **** (90% 成功率)
   ```
   // Include version in the update request
req := &UpdateRequest{Id: id, Data: newData, Version: currentVersion}
_, err := client.Update(ctx, req)
if status.Code(err) == codes.Aborted {
    // handle conflict
}
   ```

## 无效尝试

- **** — The version is outdated; retrying with the same version will fail again. (100% 失败率)
- **** — This can lead to lost updates and data inconsistency. (90% 失败率)
