You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A race condition exists in the redis cluster client involving c.activeAddrs(a slice that stores redis node addresses). Specifically, the cluster client’s GC function writes to c.activeAddrs, while concurrently, callers may invoke the Addrs function to read from it.
Write path
Function GC overwrites the activeAddrs from its beginning.
Run the new test in the patch: go test -race -v --timeout 1m -run "TestGinkgoSuite"
Context (Environment)
The race condition has been detected in the real Redis cluster and is also reproducible with the above steps.
Possible Implementation
One possible solution is to modify the func (c *clusterNodes) Addrs() ([]string, error) function to return a copied slice instead of a reference.
func (c*clusterNodes) Addrs() ([]string, error) {
...if!closed {
iflen(c.activeAddrs) >0 {
addrs=c.activeAddrs// make a copy
} else {
addrs=c.addrs// make a copy
}
}
The fix might slightly increase the runtime of the Addrs() function, as copying the original slice generally takes more time than creating a simple reference. However, this impact appears to be negligible. Details are as follows:
Benchmarking on an "AMD EPYC 7B13" host shows that copying a slice of 500 addresses takes approximately 2.5 microseconds.
The existing callers of the Addr() function, such as ClusterClient.loadState, clusterNodes.Random, and ClusterClient.cmdsInfo, are not on the perf critical path. Therefore, adding a few microseconds is unlikely to have any significant impact.
The text was updated successfully, but these errors were encountered:
A race condition exists in the redis cluster client involving c.activeAddrs(a slice that stores redis node addresses). Specifically, the cluster client’s GC function writes to c.activeAddrs, while concurrently, callers may invoke the Addrs function to read from it.
Write path
Function GC overwrites the activeAddrs from its beginning.
Read path
The function Addrs() returns a reference to a string slice. The returned addrs references either c.activeAddrs or c.addrs from the original object.
Expected Behavior
There is no race condition between the "addrs" consumers and the GC function.
Current Behavior
Possible Solution
Return a new copy of the addr slice instead of a reference to the original slice.
Steps to Reproduce
go test -race -v --timeout 1m -run "TestGinkgoSuite"
Context (Environment)
The race condition has been detected in the real Redis cluster and is also reproducible with the above steps.
Possible Implementation
One possible solution is to modify the func (c *clusterNodes) Addrs() ([]string, error) function to return a copied slice instead of a reference.
The fix might slightly increase the runtime of the Addrs() function, as copying the original slice generally takes more time than creating a simple reference. However, this impact appears to be negligible. Details are as follows:
The text was updated successfully, but these errors were encountered: