Skip to content
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

testing: race in outputting to the root io.Writer #18741

Closed
dsnet opened this issue Jan 22, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@dsnet
Copy link
Member

commented Jan 22, 2017

Using Go1.7.4.

Consider the following test:

func Test(t *testing.T) {
	var wg sync.WaitGroup
	defer wg.Wait()
	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			t.Run(fmt.Sprintf("LongLongLongLongName%d", i), func(t *testing.T) {})
		}(i)
	}
}

On some invocations, I see something like:

=== RUN   Test/LongLongLongLongName48
=== RUN   Test/LongLon=== RUN   Test/LongLongLongLongName50
gLongLongName49
=== RUN   Test/LongLongLongLongName51

In testing.go, we directly write "=== RUN %s\n" directly to the root's io.Writer (which is os.Stdout). Although it is safe to concurrently write to os.Stdout, the results can sometimes be non-sensical.

Instead, we should acquire the root's lock before writing.

@dsnet dsnet added this to the Go1.9 milestone Jan 22, 2017

@dsnet dsnet added the NeedsFix label Jan 22, 2017

@gopherbot

This comment has been minimized.

Copy link

commented Jan 24, 2017

CL https://golang.org/cl/35556 mentions this issue.

@gopherbot gopherbot closed this in 7f31971 Feb 1, 2017

@golang golang locked and limited conversation to collaborators Feb 1, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.