Skip to content

Commit

Permalink
use atomic bool to be concurrent safe
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmad Karimi <[email protected]>
  • Loading branch information
therealak12 committed Oct 5, 2023
1 parent 8642367 commit 310dc2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions internal/contour/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package contour
import (
"context"
"reflect"
"sync/atomic"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -61,7 +62,7 @@ type EventHandler struct {

syncTracker *synctrack.SingleFileTracker

initialDagBuilt bool
initialDagBuilt atomic.Bool
}

func NewEventHandler(config EventHandlerConfig, upstreamHasSynced cache.InformerSynced) *EventHandler {
Expand Down Expand Up @@ -112,7 +113,7 @@ func (e *EventHandler) NeedLeaderElection() bool {
}

func (e *EventHandler) HasBuiltInitialDag() bool {
return e.initialDagBuilt
return e.initialDagBuilt.Load()

Check warning on line 116 in internal/contour/handler.go

View check run for this annotation

Codecov / codecov/patch

internal/contour/handler.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}

// Implements leadership.NeedLeaderElectionNotification
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 310dc2f

Please sign in to comment.