Skip to content

Commit d0fb810

Browse files
shawnwgitndyakov
andauthored
Fix race condition in clusterNodes.Addrs() (#3219)
Resolve a race condition in the clusterNodes.Addrs() method. Previously, the method returned a reference to a string slice, creating the potential for concurrent reads by the caller while the slice was being modified by the garbage collection process. Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent 1139bc3 commit d0fb810

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

osscluster.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,11 @@ func (c *clusterNodes) Addrs() ([]string, error) {
487487
closed := c.closed //nolint:ifshort
488488
if !closed {
489489
if len(c.activeAddrs) > 0 {
490-
addrs = c.activeAddrs
490+
addrs = make([]string, len(c.activeAddrs))
491+
copy(addrs, c.activeAddrs)
491492
} else {
492-
addrs = c.addrs
493+
addrs = make([]string, len(c.addrs))
494+
copy(addrs, c.addrs)
493495
}
494496
}
495497
c.mu.RUnlock()

0 commit comments

Comments
 (0)