Skip to content

Fix flaky TestIsStdinIsReadableWithAPipe by draining stdin in the test helper - #4140

Merged
DrJosh9000 merged 1 commit into
mainfrom
fix-stdin-readable-pipe-test
Jul 30, 2026
Merged

Fix flaky TestIsStdinIsReadableWithAPipe by draining stdin in the test helper#4140
DrJosh9000 merged 1 commit into
mainfrom
fix-stdin-readable-pipe-test

Conversation

@claude

@claude claude Bot commented Jul 30, 2026

Copy link
Copy Markdown

Requested by Dan Niknam · Slack thread

Description

TestIsStdinIsReadableWithAPipe is intermittently flaky on Windows.

Before: the test spawns a helper with piped input (echo output | helper), but the helper never reads that input. On Windows, when the helper exits with data still unread in the pipe, the upstream writer (echo) hits a broken pipe and prints The process tried to write to a nonexistent pipe.. That message leaks into the parent's CombinedOutput, so the captured output is no longer exactly "true" and the assertion fails intermittently.

After: the helper drains stdin before exiting, so the pipe closes cleanly, echo never hits a broken pipe, and the assertion sees exactly "true".

Context

Requested via the Slack thread linked above.

This fixes one of four recently-observed CI flakes on main. The other three (a Linux hook-hang, a Linux fork/exec: bad file descriptor, and a Windows GetExitCodeProcess: handle is invalid) form a separate concurrent-spawn fd/handle-race cluster that did not reproduce under local stress testing and are being investigated separately. They are intentionally out of scope here.

Changes

Add io.Copy(io.Discard, os.Stdin) in the TestMain helper's case "1", immediately after the IsReadable() call, to drain stdin before the helper exits. This is harmless for the nil-stdin and file-redirect helper invocations (there is simply nothing, or a bounded amount, to drain). Production code in stdin.go is unchanged — this is a test-only fix.

Testing

  • Tests have run locally (with go test ./...)
  • Code is formatted (with go tool gofumpt -extra -w .)

Verified locally with Go 1.26.5:

  • go build ./... — passes
  • go vet ./internal/stdin/... — passes
  • go test ./internal/stdin/... -count=3 — passes

Disclosures / Credits

Claude Code produced this test-helper change.


Generated by Claude Code

…t helper

On Windows, the piped-input case (echo output | helper) left data unread in
the pipe. When the helper exited without draining, the upstream writer failed
with 'The process tried to write to a nonexistent pipe.' and that message
leaked into the parent's CombinedOutput, corrupting the exact "true"
assertion. Drain stdin with io.Copy(io.Discard, os.Stdin) before exiting so
the pipe closes cleanly.
@DrJosh9000 DrJosh9000 added the internal Non-user facing, internal change. label Jul 30, 2026
@claude
claude Bot marked this pull request as ready for review July 30, 2026 05:28
@claude
claude Bot requested review from a team as code owners July 30, 2026 05:28
@DrJosh9000
DrJosh9000 merged commit 94c3a4a into main Jul 30, 2026
4 of 5 checks passed
@DrJosh9000
DrJosh9000 deleted the fix-stdin-readable-pipe-test branch July 30, 2026 05:28
@zhming0 zhming0 mentioned this pull request Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Non-user facing, internal change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants