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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  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: }.

无效尝试

常见但无效的做法:

  1. 85% 失败

    Once the stream is reset, every subsequent Send fails; continuing wastes CPU and delays cleanup.

  2. 90% 失败

    CloseSend signals end of client sends; calling it mid-stream terminates the stream prematurely.