From 9e04eda800b3549e237270126ecbd03e113000c7 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Tue, 27 Aug 2024 15:32:14 +0530 Subject: [PATCH] feat: fix wait function to copy the array before changing it Signed-off-by: Manan Gupta --- go/vt/discovery/keyspace_events.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go/vt/discovery/keyspace_events.go b/go/vt/discovery/keyspace_events.go index d477228202b..3a4d517f036 100644 --- a/go/vt/discovery/keyspace_events.go +++ b/go/vt/discovery/keyspace_events.go @@ -19,6 +19,7 @@ package discovery import ( "context" "fmt" + "slices" "sync" "time" @@ -715,7 +716,10 @@ func (kew *KeyspaceEventWatcher) GetServingKeyspaces() []string { } // WaitForConsistentKeyspaces waits for the given set of keyspaces to be marked consistent. -func (kew *KeyspaceEventWatcher) WaitForConsistentKeyspaces(ctx context.Context, keyspaces []string) error { +func (kew *KeyspaceEventWatcher) WaitForConsistentKeyspaces(ctx context.Context, ksList []string) error { + // We don't want to change the original keyspace list that we receive so we clone it + // before we empty it elements down below. + keyspaces := slices.Clone(ksList) for { // We empty keyspaces as we find them to be consistent. allConsistent := true