go
network_error
ai_generated
true
rpc 错误:code = Internal desc = grpc: 发送消息失败: 流被 RST_STREAM 终止
rpc error: code = Internal desc = grpc: failed to send message: stream terminated by RST_STREAM
ID: go/grpc-stream-send-after-close
80%修复率
84%置信度
0证据数
2024-12-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.x | active | — | — | — |
根因分析
服务端流或双向流处理函数在流已被客户端关闭或先前错误关闭后调用了 Send。HTTP/2 流已被重置。
English
A server-streaming or bidi-streaming handler called Send after the stream was already closed by the client or by an earlier error. The HTTP/2 stream was reset.
解决方案
-
92% 成功率
Check the error from Send and return immediately: if err := stream.Send(msg); err != nil { return status.Errorf(codes.Internal, "send: %v", err) }. -
88% 成功率
Watch ctx.Done() in the streaming loop and exit gracefully when the client disconnects: select { case <-ctx.Done(): return ctx.Err(); default: }.
无效尝试
常见但无效的做法:
-
85% 失败
Once the stream is reset, every subsequent Send fails; continuing wastes CPU and delays cleanup.
-
90% 失败
CloseSend signals end of client sends; calling it mid-stream terminates the stream prematurely.