mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
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 <nedyalko.dyakov@gmail.com>
This commit is contained in:
parent
1139bc3aa9
commit
d0fb810b13
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user