From 24426700545c3a87c8481adceb07b36988eef542 Mon Sep 17 00:00:00 2001 From: Mike Boiko Date: Mon, 11 May 2026 16:13:56 -0600 Subject: [PATCH] fix: move wg.Add(1) before goroutine launch to prevent negative WaitGroup counter The goroutines for copying stdout/stderr were launched with defer wg.Done() before wg.Add(1) was called. If a goroutine completed before Add(1) executed, Done() would decrement the counter below zero, causing a panic. Fixes https://github.com/alajmo/mani/issues/124 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- core/exec/text.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/exec/text.go b/core/exec/text.go index 9f20156..30b7da7 100644 --- a/core/exec/text.go +++ b/core/exec/text.go @@ -148,6 +148,7 @@ func RunTextCmd( } // Copy over commands STDOUT. + wg.Add(1) go func(client Client) { defer wg.Done() var err error @@ -161,9 +162,9 @@ func RunTextCmd( fmt.Fprintf(stderr, "%s", err) } }(t.client) - wg.Add(1) // Copy over tasks's STDERR. + wg.Add(1) go func(client Client) { defer wg.Done() var err error @@ -177,7 +178,6 @@ func RunTextCmd( fmt.Fprintf(stderr, "%s", err) } }(t.client) - wg.Add(1) wg.Wait()