Skip to content

Conversation

@mrnugget
Copy link
Contributor

@mrnugget mrnugget commented Sep 6, 2021

This might've been the cause for the flaky test we saw (example failure here).

The docs say that cmd.Run() in combination with StdoutPipe/StderrPipe is wrong:

Wait will close the pipe after seeing the command exit, so most callers
need not close the pipe themselves. It is thus incorrect to call Wait
before all reads from the pipe have completed. For the same reason, it
is incorrect to call Run when using StdoutPipe. See the example for
idiomatic usage.

See: https://pkg.go.dev/os/exec#example-Cmd.StdoutPipe

This might've been the cause for the flaky test we saw, because the docs
say that `cmd.Run()` in combination with `StdoutPipe`/`StderrPipe` is
wrong:

> `Wait` will close the pipe after seeing the command exit, so most callers
> need not close the pipe themselves. It is thus incorrect to call `Wait`
> before all reads from the pipe have completed. For the same reason, it
> is incorrect to call `Run` when using `StdoutPipe`. See the example for
> idiomatic usage.

See: https://pkg.go.dev/os/exec#example-Cmd.StdoutPipe
@mrnugget mrnugget requested a review from a team September 6, 2021 08:55
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

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

Great catch! Even if it doesn't fix the flake, this is a good improvement!

@mrnugget mrnugget merged commit 2275dcf into main Sep 6, 2021
@mrnugget mrnugget deleted the mrn/correctly-pipe-output branch September 6, 2021 09:09
scjohns pushed a commit that referenced this pull request Apr 24, 2023
This might've been the cause for the flaky test we saw, because the docs
say that `cmd.Run()` in combination with `StdoutPipe`/`StderrPipe` is
wrong:

> `Wait` will close the pipe after seeing the command exit, so most callers
> need not close the pipe themselves. It is thus incorrect to call `Wait`
> before all reads from the pipe have completed. For the same reason, it
> is incorrect to call `Run` when using `StdoutPipe`. See the example for
> idiomatic usage.

See: https://pkg.go.dev/os/exec#example-Cmd.StdoutPipe
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