Skip to content

core/bazel: fix race#135

Open
sywhang wants to merge 1 commit into
mainfrom
race-core-bazel
Open

core/bazel: fix race#135
sywhang wants to merge 1 commit into
mainfrom
race-core-bazel

Conversation

@sywhang

@sywhang sywhang commented Jun 30, 2026

Copy link
Copy Markdown

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.

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.
@sywhang sywhang requested review from a team as code owners June 30, 2026 23:05
Comment thread core/bazel/stream.go

select {
case <-ctx.Done():
<-done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blocks on copying goroutine, in which case it does not make any sense to have a goroutine at all but rather block on a main thread.
what we need to have instead is a cancellable Copy, or at least a cancellable io.Reader.
This wrapper is better than nothing on pure blocking reads: https://github.com/uber/tango/pull/108/changes#diff-279a703791b2ff1b50139ea545c8aca00928b154a414330229e4891ec895aaf2

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main thread is already blocked before we call errgroup.Wait() because we're calling cmd.Wait().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

race in core/bazel

3 participants