Skip to content

Commit 96d8329

Browse files
committed
lock mutex only for balancer.Next()
1 parent bd82e96 commit 96d8329

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

internal/cluster/cluster.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,14 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
282282
}
283283
}
284284

285-
c.balancerMtx.RLock()
286-
defer c.balancerMtx.RUnlock()
287-
288285
for {
289286
select {
290287
case <-ctx.Done():
291288
return nil, errors.WithStackTrace(ctx.Err())
292289
default:
290+
c.balancerMtx.RLock()
293291
cc = c.config.Balancer().Next()
292+
c.balancerMtx.RUnlock()
294293
if cc == nil {
295294
return nil, errors.WithStackTrace(ErrClusterEmpty)
296295
}

0 commit comments

Comments
 (0)