From 6b56aa1e42f8cf3308c811b948670704ae8e0e06 Mon Sep 17 00:00:00 2001 From: shawnw Date: Sun, 5 Jan 2025 11:50:03 -0800 Subject: [PATCH] Fix race condition in clusterNodes.Addrs() 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. --- osscluster.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osscluster.go b/osscluster.go index 72e922a80..188f50359 100644 --- a/osscluster.go +++ b/osscluster.go @@ -487,9 +487,11 @@ func (c *clusterNodes) Addrs() ([]string, error) { closed := c.closed //nolint:ifshort if !closed { if len(c.activeAddrs) > 0 { - addrs = c.activeAddrs + addrs = make([]string, len(c.activeAddrs)) + copy(addrs, c.activeAddrs) } else { - addrs = c.addrs + addrs = make([]string, len(c.addrs)) + copy(addrs, c.addrs) } } c.mu.RUnlock()