Skip to content

core/bazel: fix race#135

Open
sywhang wants to merge 7 commits into
mainfrom
race-core-bazel
Open

core/bazel: fix race#135
sywhang wants to merge 7 commits into
mainfrom
race-core-bazel

Conversation

@sywhang

@sywhang sywhang commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fix a race during Bazel query cancellation by replacing concurrent pipe readers with file-backed stdout/stderr capture.

This avoids buffer races and inherited-pipe hangs while preserving live stderr, context cancellation, SIGTERM/SIGKILL escalation, and context-aware parsing.

Added regression coverage for cancellation and descendant processes holding output descriptors.

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 Outdated

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
Contributor 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().

@sywhang sywhang requested a review from sbalabanov July 8, 2026 17:55
@sywhang sywhang force-pushed the race-core-bazel branch from c6764db to 705ebe6 Compare July 9, 2026 02:12
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.

3 participants