Skip to content

fix(longops): drain process output before Wait to avoid truncated lines - #151

Merged
gnacho merged 1 commit into
mainfrom
fix/150-longops-output-race
Oct 13, 2026
Merged

gnacho merged 1 commit into
mainfrom
fix/150-longops-output-race

Conversation

@gnacho

@gnacho gnacho commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Fixes #150.

Manager.watch called cmd.Wait() before draining the stdout scanner. With StdoutPipe, Wait closes the read end of the pipe as soon as the process exits (documented in os/exec: it is incorrect to call Wait before all reads from the pipe have completed), so whatever was still buffered could be lost. The release CI for v2.9.28 hit exactly this on the arm64 runner: TestStartCapturesOutput got lines=[] for a printf that wrote two lines and exited immediately.

The fix reorders the sequence: drain the scanner to EOF first, then reap with Wait. EOF only happens after the process closes its stdout, so all lines are captured before the op is marked done. This also protects real rewrite/replication progress lines from truncation.

Verification: go vet clean; go test -race -run "TestStart|TestCancel" -count=100 ./internal/longops/ pass (100 iterations); go test -race -count=3 ./internal/longops/ pass; full go test ./internal/... pass.

With StdoutPipe, Wait closes the read end of the pipe as soon as the
process exits, so calling Wait before draining the scanner could lose
whatever was still buffered: on a loaded arm64 runner the release CI hit
lines=[] for a printf that wrote and exited immediately (#150). Read to
EOF first, then reap.

Closes #150
@gnacho
gnacho merged commit c109fcb into main Oct 13, 2026
3 checks passed
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.

TestStartCapturesOutput is flaky on CI (arm64): empty lines on completion

1 participant