Skip to content

Fix grpc middleware interceptor not PostCall-ing when a streaming RPC with non-streaming server finishes successfully. #725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions interceptors/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func StreamClientInterceptor(reportable ClientReportable) grpc.StreamClientInter
reporter.PostCall(err, time.Since(r.startTime))
return nil, err
}
return &monitoredClientStream{ClientStream: clientStream, startTime: r.startTime, reporter: reporter}, nil
return &monitoredClientStream{ClientStream: clientStream, startTime: r.startTime, hasServerStream: desc.ServerStreams, reporter: reporter}, nil
}
}

Expand All @@ -47,6 +47,7 @@ type monitoredClientStream struct {
grpc.ClientStream

startTime time.Time
hasServerStream bool
reporter Reporter
}

Expand All @@ -62,13 +63,17 @@ func (s *monitoredClientStream) RecvMsg(m any) error {
err := s.ClientStream.RecvMsg(m)
s.reporter.PostMsgReceive(m, err, time.Since(start))

if err == nil {
return nil
}
var postErr error
if err != io.EOF {
postErr = err
if s.hasServerStream {
if err == nil {
return nil
}
var postErr error
if err != io.EOF {
postErr = err
}
s.reporter.PostCall(postErr, time.Since(s.startTime))
} else {
s.reporter.PostCall(err, time.Since(s.startTime))
}
s.reporter.PostCall(postErr, time.Since(s.startTime))
return err
return err
}
Loading