# rpc 错误：代码 = AlreadyExists 描述 = 服务 pb.OrderService 重复注册

- **ID:** `go/grpc-already-exists`
- **领域:** go
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在同一个 grpc.Server 上两次调用了 RegisterOrderServiceServer，或两个服务端实例共享了注册表。gRPC 在重复注册服务时会 panic。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| google.golang.org/grpc v1.46+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   s := grpc.NewServer()
pb.RegisterOrderServiceServer(s, svc)
// do not register again elsewhere
   ```
2. **** (85% 成功率)
   ```
   var once sync.Once
once.Do(func() { pb.RegisterOrderServiceServer(s, svc) })
   ```

## 无效尝试

- **** — Recovering hides the bug; the second registration still fails and the server state is inconsistent. (80% 失败率)
- **** — Multiple servers on one listener conflict; only one can bind the port, and requests route unpredictably. (75% 失败率)
