diff --git a/tools/cmd/debug/heal_common.go b/tools/cmd/debug/heal_common.go index 97ab67756..82910ba1f 100644 --- a/tools/cmd/debug/heal_common.go +++ b/tools/cmd/debug/heal_common.go @@ -101,6 +101,10 @@ func (h *healer) Reset() { } func (h *healer) heal(args []string) { + // Wait must be called after cancel (so the defer must happen first) + wg := new(sync.WaitGroup) + defer wg.Wait() + ctx := cmdutil.ContextForMainProcess(context.Background()) ctx, cancel, _ := api.ContextWithBatchData(ctx) defer cancel() @@ -177,9 +181,6 @@ func (h *healer) heal(args []string) { }, } - wg := new(sync.WaitGroup) - defer wg.Wait() - h.submit = make(chan []messaging.Message) wg.Add(1) go h.submitLoop(wg)