Skip to content

Commit f54c60d

Browse files
committed
* Fixed locking of cluster during call cluster.Get
1 parent 4936763 commit f54c60d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed locking of cluster during call `cluster.Get`
2+
13
## v3.19.1
24
* Simplified README.md for godoc documentation in pkg.go.dev
35

internal/cluster/cluster.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ func parseOptions(opts ...crudOption) *crudOptionsHolder {
131131
}
132132

133133
type Getter interface {
134-
// Get gets conn from cluster
134+
// Get returns next available connection.
135+
// It returns error on given deadline cancellation or when cluster become closed.
135136
Get(ctx context.Context) (cc conn.Conn, err error)
136137
}
137138

@@ -268,6 +269,8 @@ func (c *cluster) get(ctx context.Context) (cc conn.Conn, err error) {
268269
// It returns error on given deadline cancellation or when cluster become closed.
269270
func (c *cluster) Get(ctx context.Context) (cc conn.Conn, err error) {
270271
var cancel context.CancelFunc
272+
// without client context deadline lock limited on MaxGetConnTimeout
273+
// cluster endpoints cannot be updated at this time
271274
ctx, cancel = context.WithTimeout(ctx, MaxGetConnTimeout)
272275
defer cancel()
273276

@@ -284,10 +287,12 @@ func (c *cluster) Get(ctx context.Context) (cc conn.Conn, err error) {
284287
}
285288
}()
286289

290+
// wait lock for read during Get
291+
c.mu.RLock()
292+
defer c.mu.RUnlock()
293+
287294
if e, ok := ContextEndpoint(ctx); ok {
288-
c.mu.RLock()
289295
cc, ok = c.endpoints[e.NodeID()]
290-
c.mu.RUnlock()
291296
if ok && cc.IsState(
292297
conn.Created,
293298
conn.Online,

0 commit comments

Comments
 (0)