volume: shuffle a copy of cached replica locations for proxy reads

LookupVolumeId serves cached location slices shared between lookups; shuffling in place races with concurrent proxied reads of the same volume.
This commit is contained in:
chrislusf committed 2026-10-26 01:47:00 -07:00
1 parent 63dfda3412
commit a7b0aa8926
1 file changed
+6 -2
+6 -2
View File
@@ -12,6 +12,7 @@ import (
"net/http"
"net/url"
"path/filepath"
"slices"
"strconv"
"strings"
"sync/atomic"
@@ -77,9 +78,12 @@ func (vs *VolumeServer) proxyReqToTargetServer(w http.ResponseWriter, r *http.Re
return
}
if len(lookupResult.Locations) >= 2 {
rand.Shuffle(len(lookupResult.Locations), func(i, j int) {
lookupResult.Locations[i], lookupResult.Locations[j] = lookupResult.Locations[j], lookupResult.Locations[i]
// cached locations are shared between lookups, so shuffle a copy
locations := slices.Clone(lookupResult.Locations)
rand.Shuffle(len(locations), func(i, j int) {
locations[i], locations[j] = locations[j], locations[i]
})
lookupResult.Locations = locations
}
var targetUrl *url.URL
location := fmt.Sprintf("%s:%d", vs.store.Ip, vs.store.Port)