Skip to content

Commit

Permalink
internal/xdscache: Generate uuid for snapshot version (#5819)
Browse files Browse the repository at this point in the history
Snapshotter had a data race reading/writing the snapshot version between
threads. This version is not in practice used for the contour xDS server
DiscoveryResponse versions but is in the go-control-plane version.

Fixes: #5482

Signed-off-by: Sunjay Bhatia <[email protected]>
  • Loading branch information
sunjayBhatia authored Oct 10, 2023
1 parent 2765c72 commit 8f6aff1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 78 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/go-logr/logr v1.2.4
github.com/google/go-cmp v0.5.9
github.com/google/go-github/v48 v48.2.0
github.com/google/uuid v1.3.1
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/onsi/ginkgo/v2 v2.12.1
Expand Down Expand Up @@ -79,7 +80,6 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
Expand Down
22 changes: 2 additions & 20 deletions internal/xdscache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
package xdscache

import (
"math"
"reflect"
"strconv"
"sync"

envoy_types "github.com/envoyproxy/go-control-plane/pkg/cache/types"
envoy_resource_v3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/google/uuid"
"github.com/projectcontour/contour/internal/dag"
"github.com/sirupsen/logrus"
)
Expand All @@ -36,9 +35,6 @@ type SnapshotHandler struct {
// resources holds the cache of xDS contents.
resources map[envoy_resource_v3.Type]ResourceCache

// snapshotVersion holds the current version of the snapshot.
snapshotVersion int64

snapshotters []Snapshotter
snapLock sync.Mutex

Expand Down Expand Up @@ -75,7 +71,7 @@ func (s *SnapshotHandler) OnChange(root *dag.DAG) {
// the Contour XDS caches.
func (s *SnapshotHandler) generateNewSnapshot() {
// Generate new snapshot version.
version := s.newSnapshotVersion()
version := uuid.NewString()

// Convert caches to envoy xDS Resources.
resources := map[envoy_resource_v3.Type][]envoy_types.Resource{
Expand All @@ -97,20 +93,6 @@ func (s *SnapshotHandler) generateNewSnapshot() {
}
}

// newSnapshotVersion increments the current snapshotVersion
// and returns as a string.
func (s *SnapshotHandler) newSnapshotVersion() string {

// Reset the snapshotVersion if it ever hits max size.
if s.snapshotVersion == math.MaxInt64 {
s.snapshotVersion = 0
}

// Increment the snapshot version & return as string.
s.snapshotVersion++
return strconv.FormatInt(s.snapshotVersion, 10)
}

// asResources casts the given slice of values (that implement the envoy_types.Resource
// interface) to a slice of envoy_types.Resource. If the length of the slice is 0, it
// returns nil.
Expand Down
57 changes: 0 additions & 57 deletions internal/xdscache/snapshot_test.go

This file was deleted.

0 comments on commit 8f6aff1

Please sign in to comment.