go network_error ai_generated true

rpc error: code = Internal desc = grpc: failed to send message: stream terminated by RST_STREAM

ID: go/grpc-stream-send-after-close

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-12-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active — — —

Root Cause

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

中文

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

Workarounds

  1. 92% success
    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% success
    Watch ctx.Done() in the streaming loop and exit gracefully when the client disconnects: select { case <-ctx.Done(): return ctx.Err(); default: }.

Dead Ends

Common approaches that don't work:

  1. 85% fail

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

  2. 90% fail

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