cmd/strelaypoolsrv: Fix relay shuffling (fixes #6936) (#6935)

When cap(permanentRelays) >= len(permanentRelays) + len(knownRelays),

	append(permanentRelays, knownRelays...)

returns a slice of the array underlying permanentRelays. The subsequent
rand.Shuffle then mixes the permanent and known relays. Sequential
requests may cause strelaypoolsrv to forget its permanent relays. Worse,
concurrent requests may cause shuffling of the same slice on multiple
processors concurrently.

Co-authored-by: greatroar <@>
This commit is contained in:
greatroar
2020-08-27 15:51:58 +02:00
committed by GitHub
co-authored by greatroar <@>
parent c74df2d588
commit 0941ce76b7
2 changed files with 71 additions and 1 deletions
+4 -1
View File
@@ -314,8 +314,11 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
func handleGetRequest(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json; charset=utf-8")
mut.RLock()
relays := append(permanentRelays, knownRelays...)
relays := make([]*relay, len(permanentRelays)+len(knownRelays))
n := copy(relays, permanentRelays)
copy(relays[n:], knownRelays)
mut.RUnlock()
// Shuffle