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 1cfbf4e commit 93ad0b6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/contour/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

Check failure on line 28 in internal/contour/handler.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/k8s"
"sync/atomic"
)

type EventHandlerConfig struct {
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()
}

// 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 93ad0b6

Please sign in to comment.