From 471df1c1f73435ce30f364fcfb2ef5b2aabcd2ea Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Tue, 30 Jun 2026 16:02:09 -0700 Subject: [PATCH] core/bazel: fix race There's a race in `streamOutput` and `streamAndParseTargets` where the stderr buffer was being read / written concurrently. When the context gets cancelled and bails, it's trying to read the buffer while it's still being written to by the other goroutine. The streaming goroutine should block until the other goroutine exits, so that it doesn't attempt to read the byte buffer concurrently. Fixes #134. --- core/bazel/stream.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/bazel/stream.go b/core/bazel/stream.go index 2e78fd7..959717c 100644 --- a/core/bazel/stream.go +++ b/core/bazel/stream.go @@ -32,6 +32,7 @@ func streamOutput(ctx context.Context, src io.Reader, dst io.Writer) error { select { case <-ctx.Done(): + <-done return ctx.Err() case err := <-done: return err @@ -52,6 +53,7 @@ func streamAndParseTargets(ctx context.Context, src io.Reader, dst io.Writer) (* select { case <-ctx.Done(): + <-done return nil, ctx.Err() case res := <-done: return res.queryResult, res.err