# rpc 错误：code = Internal desc = grpc: 发送消息失败: 流被 RST_STREAM 终止

- **ID:** `go/grpc-stream-send-after-close`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务端流或双向流处理函数在流已被客户端关闭或先前错误关闭后调用了 Send。HTTP/2 流已被重置。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   Check the error from Send and return immediately: if err := stream.Send(msg); err != nil { return status.Errorf(codes.Internal, "send: %v", err) }.
   ```
2. **** (88% 成功率)
   ```
   Watch ctx.Done() in the streaming loop and exit gracefully when the client disconnects: select { case <-ctx.Done(): return ctx.Err(); default: }.
   ```

## 无效尝试

- **** — Once the stream is reset, every subsequent Send fails; continuing wastes CPU and delays cleanup. (85% 失败率)
- **** — CloseSend signals end of client sends; calling it mid-stream terminates the stream prematurely. (90% 失败率)
