From 5e07643bedfedc7b736b60aa418a831b807d6f59 Mon Sep 17 00:00:00 2001 From: Matthew Pilot Date: Mon, 20 Jul 2026 11:31:51 +0000 Subject: [PATCH] fix(daemon): register echo service listener with bgWG (PILOT-88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The startEchoService goroutine was the last daemon-scoped goroutine not registered with d.bgWG. During graceful shutdown, the echo listener exited correctly (select on d.stopCh) but was unaccounted for in the WaitGroup — meaning bgWG.Wait() could return before the listener had fully stopped if it was racing with port teardown. This is a continuation of the mechanical sweep described in PILOT-88: the core loops (routeLoop, trustRepublishLoop, etc.) already used bgWG, but the echo service was missed. Adding d.bgWG.Add(1) / defer d.bgWG.Done() ensures the shutdown sequence waits for the echo listener to exit before tearing down port infrastructure. Closes PILOT-88 --- pkg/daemon/services.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/daemon/services.go b/pkg/daemon/services.go index eaa7b316..1cd4ec81 100644 --- a/pkg/daemon/services.go +++ b/pkg/daemon/services.go @@ -145,7 +145,9 @@ func (d *Daemon) startEchoService() error { if err != nil { return err } + d.bgWG.Add(1) go func() { + defer d.bgWG.Done() for { select { case conn, ok := <-ln.AcceptCh: