Skip to content

Fix pipe read race in exec_service server#12

Merged
afq984 merged 1 commit intogoogle:mainfrom
afq984:push-mmtkuyssoxxr
Apr 8, 2026
Merged

Fix pipe read race in exec_service server#12
afq984 merged 1 commit intogoogle:mainfrom
afq984:push-mmtkuyssoxxr

Conversation

@afq984
Copy link
Copy Markdown
Collaborator

@afq984 afq984 commented Apr 8, 2026

SetReadDeadline(time.Now()) can fire before the read loop consumes buffered pipe data. Go's poller checks the deadline before attempting syscall.Read, so ErrDeadlineExceeded is returned and buffered output is silently dropped.

Fix: kill the process group after cmd.Wait() so background children close their inherited pipe fds, letting the read loop reach EOF without any deadline. A 100ms deadline fallback handles the rare case of children that escaped the process group (e.g. via setsid).

Reproducer (fails 10/10 without the fix):

bazel test //exec_service/cmd/exec_client:exec_client_test \
    --test_arg=-test.run=TestStderrOutput \
    --test_arg=-test.count=500 \
    --test_arg=-test.cpu=1 \
    --runs_per_test=10 --local_test_jobs=10

SetReadDeadline(time.Now()) can fire before the read loop consumes
buffered pipe data. Go's poller checks the deadline before attempting
syscall.Read, so ErrDeadlineExceeded is returned and buffered output
is silently dropped.

Fix: kill the process group after cmd.Wait() so background children
close their inherited pipe fds, letting the read loop reach EOF
without any deadline. A 100ms deadline fallback handles the rare case
of children that escaped the process group (e.g. via setsid).

Reproducer (fails 10/10 without the fix):

    bazel test //exec_service/cmd/exec_client:exec_client_test \
        --test_arg=-test.run=TestStderrOutput \
        --test_arg=-test.count=500 \
        --test_arg=-test.cpu=1 \
        --runs_per_test=10 --local_test_jobs=10
@afq984 afq984 enabled auto-merge (rebase) April 8, 2026 00:46
@afq984 afq984 disabled auto-merge April 8, 2026 00:59
@afq984 afq984 merged commit c3d94a5 into google:main Apr 8, 2026
3 checks passed
@afq984 afq984 deleted the push-mmtkuyssoxxr branch April 8, 2026 00:59
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.

1 participant