Skip to content

Commit

Permalink
don't add defer func if stats handler is nil (grpc#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirk authored and menghanl committed May 2, 2017
1 parent 0eb507a commit 0914b46
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
8 changes: 3 additions & 5 deletions call.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,15 @@ func invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
FailFast: c.failFast,
}
sh.HandleRPC(ctx, begin)
}
defer func() {
if sh != nil {
defer func() {
end := &stats.End{
Client: true,
EndTime: time.Now(),
Error: e,
}
sh.HandleRPC(ctx, end)
}
}()
}()
}
topts := &transport.Options{
Last: true,
Delay: false,
Expand Down
16 changes: 6 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,16 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
BeginTime: time.Now(),
}
sh.HandleRPC(stream.Context(), begin)
}
defer func() {
if sh != nil {
defer func() {
end := &stats.End{
EndTime: time.Now(),
}
if err != nil && err != io.EOF {
end.Error = toRPCErr(err)
}
sh.HandleRPC(stream.Context(), end)
}
}()
}()
}
if trInfo != nil {
defer trInfo.tr.Finish()
trInfo.firstLine.client = false
Expand Down Expand Up @@ -814,18 +812,16 @@ func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transp
BeginTime: time.Now(),
}
sh.HandleRPC(stream.Context(), begin)
}
defer func() {
if sh != nil {
defer func() {
end := &stats.End{
EndTime: time.Now(),
}
if err != nil && err != io.EOF {
end.Error = toRPCErr(err)
}
sh.HandleRPC(stream.Context(), end)
}
}()
}()
}
if s.opts.cp != nil {
stream.SetSendCompress(s.opts.cp.Type())
}
Expand Down
20 changes: 10 additions & 10 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
FailFast: c.failFast,
}
sh.HandleRPC(ctx, begin)
}
defer func() {
if err != nil && sh != nil {
// Only handle end stats if err != nil.
end := &stats.End{
Client: true,
Error: err,
defer func() {
if err != nil {
// Only handle end stats if err != nil.
end := &stats.End{
Client: true,
Error: err,
}
sh.HandleRPC(ctx, end)
}
sh.HandleRPC(ctx, end)
}
}()
}()
}
gopts := BalancerGetOptions{
BlockingWait: !c.failFast,
}
Expand Down

0 comments on commit 0914b46

Please sign in to comment.