Skip to content

Commit cf49e6e

Browse files
committed
lock mutex only for c.endpoints[nodeId]
1 parent 96d8329 commit cf49e6e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

internal/cluster/cluster.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,6 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
253253
defer cancel()
254254

255255
options := parseOptions(opts...)
256-
if options.withLock {
257-
c.mu.Lock()
258-
defer c.mu.Unlock()
259-
}
260256

261257
if c.closed {
262258
return nil, errors.WithStackTrace(ErrClusterClosed)
@@ -272,7 +268,13 @@ func (c *cluster) Get(ctx context.Context, opts ...crudOption) (cc conn.Conn, er
272268
}()
273269

274270
if e, ok := ContextEndpoint(ctx); ok {
271+
if options.withLock {
272+
c.mu.RLock()
273+
}
275274
cc, ok = c.endpoints[e.NodeID()]
275+
if options.withLock {
276+
c.mu.RUnlock()
277+
}
276278
if ok && cc.IsState(
277279
conn.Created,
278280
conn.Online,

0 commit comments

Comments
 (0)