Merge pull request #308 from fireyang/master

fix bug: loop variable i captured by func literal
This commit is contained in:
Asim Aslam 2018-09-19 15:13:19 +01:00 committed by GitHub
commit 818f150b25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,8 @@ import (
"sync" "sync"
"time" "time"
"sync/atomic"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/codec" "github.com/micro/go-micro/codec"
"github.com/micro/go-micro/errors" "github.com/micro/go-micro/errors"
@ -14,7 +16,6 @@ import (
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"sync/atomic"
) )
type rpcClient struct { type rpcClient struct {
@ -322,9 +323,9 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
var gerr error var gerr error
for i := 0; i <= callOpts.Retries; i++ { for i := 0; i <= callOpts.Retries; i++ {
go func() { go func(i int) {
ch <- call(i) ch <- call(i)
}() }(i)
select { select {
case <-ctx.Done(): case <-ctx.Done():