From 60cb03785f511a30b334aeef27db03c23d8b337a Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Sat, 4 Jan 2025 10:39:18 +1300 Subject: [PATCH] genbindings: fix race condition in clang output pipe --- cmd/genbindings/clangexec.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/genbindings/clangexec.go b/cmd/genbindings/clangexec.go index e1162d2d..3af41898 100644 --- a/cmd/genbindings/clangexec.go +++ b/cmd/genbindings/clangexec.go @@ -67,13 +67,15 @@ func clangExec(ctx context.Context, clangBin, inputHeader string, cflags []strin inner, innerErr = clangStripUpToFile(pr, matcher) }() + // Go documentation says: only call cmd.Wait once all reads from the + // StdoutPipe have completed + wg.Wait() + err = cmd.Wait() if err != nil { return nil, fmt.Errorf("Command: %w", err) } - wg.Wait() - return inner, innerErr }