From 310dc2f961f0f2184ae6d727e8319a884afea3e7 Mon Sep 17 00:00:00 2001 From: Ahmad Karimi Date: Thu, 5 Oct 2023 23:16:07 +0330 Subject: [PATCH] use atomic bool to be concurrent safe Signed-off-by: Ahmad Karimi --- Makefile | 1 + internal/contour/handler.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 385325be2bf..f526cff6184 100644 --- a/Makefile +++ b/Makefile @@ -326,6 +326,7 @@ run-e2e: CONTOUR_E2E_IMAGE=$(CONTOUR_E2E_IMAGE) \ go run github.com/onsi/ginkgo/v2/ginkgo -tags=e2e -mod=readonly -skip-package=upgrade,bench -keep-going -randomize-suites -randomize-all -poll-progress-after=120s --focus '$(CONTOUR_E2E_TEST_FOCUS)' -r $(CONTOUR_E2E_PACKAGE_FOCUS) + .PHONY: cleanup-kind cleanup-kind: ./test/scripts/cleanup.sh diff --git a/internal/contour/handler.go b/internal/contour/handler.go index 716bf982053..fefe61547ad 100644 --- a/internal/contour/handler.go +++ b/internal/contour/handler.go @@ -19,6 +19,7 @@ package contour import ( "context" "reflect" + "sync/atomic" "time" "github.com/sirupsen/logrus" @@ -61,7 +62,7 @@ type EventHandler struct { syncTracker *synctrack.SingleFileTracker - initialDagBuilt bool + initialDagBuilt atomic.Bool } func NewEventHandler(config EventHandlerConfig, upstreamHasSynced cache.InformerSynced) *EventHandler { @@ -112,7 +113,7 @@ func (e *EventHandler) NeedLeaderElection() bool { } func (e *EventHandler) HasBuiltInitialDag() bool { - return e.initialDagBuilt + return e.initialDagBuilt.Load() } // Implements leadership.NeedLeaderElectionNotification @@ -205,7 +206,7 @@ func (e *EventHandler) Start(ctx context.Context) error { e.observer.OnChange(latestDAG) // Allow XDS server to start (if it hasn't already). - e.initialDagBuilt = true + e.initialDagBuilt.Store(true) // Update the status on objects. for _, upd := range latestDAG.StatusCache.GetStatusUpdates() {