Draft: wait for handleEvent to complete before ProcessTopologyChange
NewInformer() is using for len(tree.eventQueue) > 0 { sleep(10ms) } Blame · internal/informer/flux_informer.go · main · Sylva-projects / sylva-elements / sylvactl · GitLab to detect that all initial Flux object events had been processed before calling ProcessTopologyChange(). This is incorrect: a Go channel's len() drops to zero when an item is dequeued by the background event handler goroutine, not when handleEvent() finishes processing it.
There is race window between the eventHandler goroutine when it dequeues the last item and the Main goroutine checking the eventQueue empty and calling `ProcessTopologyChange()
This race window is widened by the upgrade of k8s.io/client-go to v0.35 with k8s upgrade to v1.35, where all initial list objects are drained in a single batch (not one by one as done in v0.34) , causing WaitForCacheSync to return true while all objects are still in flight not yet delivered to eventHandler.
This MR make changes to acquire and immediately release tree.lock after draining the eventQueue. This forces the main goroutine to wait until the last handleEvent() call completes before proceeding to ProcessTopologyChange().