From bd5c9e86a99b5e6150ccbc7fd5ef6edcaea86425 Mon Sep 17 00:00:00 2001
From: Ahmad Karimi <ak12hastam@gmail.com>
Date: Fri, 25 Aug 2023 20:33:25 +0330
Subject: [PATCH] call observer before setting initialDagBuilt to true

---
 internal/contour/handler.go | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/internal/contour/handler.go b/internal/contour/handler.go
index 5033b604dd0..c15e744489c 100644
--- a/internal/contour/handler.go
+++ b/internal/contour/handler.go
@@ -200,13 +200,15 @@ func (e *EventHandler) Start(ctx context.Context) error {
 
 			e.WithField("last_update", time.Since(lastDAGRebuild)).WithField("outstanding", reset()).Info("performing delayed update")
 
-			// Rebuild the DAG
+			// Build a new DAG and sends it to the Observer.
 			latestDAG := e.builder.Build()
 			lastDAGRebuild = time.Now()
+			e.observer.OnChange(latestDAG)
+
+			// Allow XDS server to start (if it hasn't already).
 			e.initialDagBuilt = true
 
-			// Send update to the Observer and StatusUpdater
-			e.observer.OnChange(latestDAG)
+			// Update the status on objects.
 			for _, upd := range latestDAG.StatusCache.GetStatusUpdates() {
 				e.statusUpdater.Send(upd)
 			}