From fde0cae1c4042d90d749f11d334dd1d122c5c25b Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 7 Aug 2019 13:22:33 -0700 Subject: [PATCH] stream: call stats handler if the attempt failed to get transport (#2962) --- stream.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stream.go b/stream.go index 4f3ca5d2..134a624a 100644 --- a/stream.go +++ b/stream.go @@ -329,13 +329,21 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth // newAttemptLocked creates a new attempt with a transport. // If it succeeds, then it replaces clientStream's attempt with this new attempt. -func (cs *clientStream) newAttemptLocked(sh stats.Handler, trInfo *traceInfo) error { +func (cs *clientStream) newAttemptLocked(sh stats.Handler, trInfo *traceInfo) (retErr error) { newAttempt := &csAttempt{ cs: cs, dc: cs.cc.dopts.dc, statsHandler: sh, trInfo: trInfo, } + defer func() { + if retErr != nil { + // This attempt is not set in the clientStream, so it's finish won't + // be called. Call it here for stats and trace in case they are not + // nil. + newAttempt.finish(retErr) + } + }() if err := cs.ctx.Err(); err != nil { return toRPCErr(err)