From dd7fde49ab6862cff6157598891f75bfffb0085e Mon Sep 17 00:00:00 2001 From: Todd Baert Date: Fri, 23 Jan 2026 15:40:29 -0500 Subject: [PATCH] fix: race condition in /stop Signed-off-by: Todd Baert --- launchpad/pkg/flagd.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/launchpad/pkg/flagd.go b/launchpad/pkg/flagd.go index 1e4b4f5..d593e8d 100644 --- a/launchpad/pkg/flagd.go +++ b/launchpad/pkg/flagd.go @@ -155,6 +155,20 @@ func stopFlagDWithoutLock() error { if err := flagdCmd.Process.Kill(); err != nil { return fmt.Errorf("failed to stop flagd: %v", err) } + + // Wait for the process to fully terminate with a timeout + done := make(chan error, 1) + go func() { + done <- flagdCmd.Wait() + }() + + select { + case <-done: + // Process fully terminated + case <-time.After(5 * time.Second): + fmt.Println("Warning: timeout waiting for flagd process to terminate") + } + flagdCmd = nil fmt.Println("flagd stopped") }