-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io: race condition with use of Pipe #67633
Comments
Looks like https://go-review.googlesource.com/c/go/+/473535 is the culprit. |
That seems to only happen because of the func TestIoPipeConcurrency(t *testing.T) {
r, w := io.Pipe()
go func() {
w.Write([]byte("hello"))
w.Close()
}()
- fmt.Printf("(%[1]T=%[1]v)", r)
buf := make([]byte, 5)
n, err := r.Read(buf)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if n != 5 {
t.Fatalf("unexpected number of bytes read: %d", n)
}
if string(buf) != "hello" {
t.Fatalf("unexpected read content: %s", buf)
}
} Before CL 473535, the print statement would print:
Now it prints:
So it has to access all the fields while printing. |
@mateusz834 Yes, exactly. That's why it cannot be passed into the mockery mock as one of the parameters like here: https://github.com/stretchr/testify/blob/v1.9.0/mock/mock.go#L939 |
Change https://go.dev/cl/588219 mentions this issue: |
Change https://go.dev/cl/588220 mentions this issue: |
Thanks for the report. I'm not sure how this race is much different than trying to |
Seems like we could fix the problem by giving I really don't know how seriously to take this. |
Or perhaps we could give |
Alternatively, we could teach |
That would need a proposal 😃 |
This comment was marked as outdated.
This comment was marked as outdated.
Yay, giving |
Not really, the method is still promoted because |
Updates #67633 Change-Id: If3da9317ba36cb8a7868db94b45c402e1793e018 Reviewed-on: https://go-review.googlesource.com/c/go/+/588219 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
Go version
go version go1.22.3 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
There is the race condition when we concurrently try to close the writer and
fmt.Printf
the reader like in the snippet test below. It was working without the race condition in v1.21.7.What did you see happen?
What did you expect to see?
The test finishes successfully without the races.
The text was updated successfully, but these errors were encountered: