Skip to content

Commit e2f3f22

Browse files
shawnwgitndyakov
andcommitted
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 053c94c commit e2f3f22

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

osscluster.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,11 @@ func (c *clusterNodes) Addrs() ([]string, error) {
465465
closed := c.closed //nolint:ifshort
466466
if !closed {
467467
if len(c.activeAddrs) > 0 {
468-
addrs = c.activeAddrs
468+
addrs = make([]string, len(c.activeAddrs))
469+
copy(addrs, c.activeAddrs)
469470
} else {
470-
addrs = c.addrs
471+
addrs = make([]string, len(c.addrs))
472+
copy(addrs, c.addrs)
471473
}
472474
}
473475
c.mu.RUnlock()

0 commit comments

Comments
 (0)