Skip to content

Commit

Permalink
Fix when resourceVersion updates multiple step in a short time, serve…
Browse files Browse the repository at this point in the history
…r will not return response

Signed-off-by: haorenfsa <[email protected]>
  • Loading branch information
haorenfsa committed Oct 25, 2024
1 parent b3bb8d7 commit eee099f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/server/stream/v3/stream.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package stream

import (
"maps"

"google.golang.org/grpc"

discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand Down Expand Up @@ -99,7 +101,7 @@ func (s *StreamState) SetWildcard(wildcard bool) {

// GetResourceVersions returns a map of current resources grouped by type URL.
func (s *StreamState) GetResourceVersions() map[string]string {
return s.resourceVersions
return maps.Clone(s.resourceVersions)
}

// SetResourceVersions sets a list of resource versions by type URL and removes the flag
Expand Down
25 changes: 25 additions & 0 deletions pkg/server/stream/v3/stream_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package stream

import "testing"

func TestStreamStateUpdateNoReace(t *testing.T) {
state := NewStreamState(false, map[string]string{
"resource": "1",
})
// simulate server side update resource from 1->2 finished, sending response
nextVersion2 := state.GetResourceVersions()
nextVersion2["resource"] = "2"

// simulate server side update resource from 2->3 finished, sending response
nextVersion3 := state.GetResourceVersions()
nextVersion3["resource"] = "3"

// 1->2 response sent to client, update sate
state.SetResourceVersions(nextVersion2)

// should updated to 2, not 3, because 3 not sent yet
result := state.GetResourceVersions()
if result["resource"] != "2" {
t.Errorf("expected version updated to 2, got %v", result["resource"])
}
}

0 comments on commit eee099f

Please sign in to comment.