From 27e5f4c8d1c74978c3395aaa67344303105bce39 Mon Sep 17 00:00:00 2001 From: Reasno Date: Wed, 10 Mar 2021 15:00:08 +0800 Subject: [PATCH] feat(kitmw): fix race condition --- kitmw/async.go | 1 + kitmw/async_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/kitmw/async.go b/kitmw/async.go index c271e98a..9ac625ec 100644 --- a/kitmw/async.go +++ b/kitmw/async.go @@ -28,6 +28,7 @@ func MakeAsyncMiddleware(logger log.Logger, concurrency int) endpoint.Middleware defer func() { limit <- struct{}{} }() + var err error ctx := opentracing.ContextWithSpan(context.Background(), span) _, err = next(ctx, request) if err != nil { diff --git a/kitmw/async_test.go b/kitmw/async_test.go index 8ff5bef9..de244e08 100644 --- a/kitmw/async_test.go +++ b/kitmw/async_test.go @@ -18,7 +18,7 @@ func TestMakeAsyncMiddleware(t *testing.T) { m := MakeAsyncMiddleware(log.NewNopLogger(), 5) f := m(func(ctx context.Context, request interface{}) (response interface{}, err error) { c.Inc() - assert.Less(t, c.Load(), 5) + assert.Less(t, int(c.Load()), 5) time.Sleep(time.Duration(rand.Float64()) * time.Second) c.Dec() return nil, nil