From 446d3fc72e7fd3027da5fb1586309487150bc963 Mon Sep 17 00:00:00 2001 From: fireyang Date: Wed, 19 Sep 2018 21:58:20 +0800 Subject: [PATCH] fix bug: loop variable i captured by func literal --- client/rpc_client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/rpc_client.go b/client/rpc_client.go index 8ed51f07..681e6298 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "sync/atomic" + "github.com/micro/go-micro/broker" "github.com/micro/go-micro/codec" "github.com/micro/go-micro/errors" @@ -14,7 +16,6 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/selector" "github.com/micro/go-micro/transport" - "sync/atomic" ) type rpcClient struct { @@ -322,9 +323,9 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac var gerr error for i := 0; i <= callOpts.Retries; i++ { - go func() { + go func(i int) { ch <- call(i) - }() + }(i) select { case <-ctx.Done():