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

dsnet opened this issue Jan 22, 2017 · 1 comment

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

dsnet opened this issue Jan 22, 2017 · 1 comment


Copy link

@dsnet dsnet 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++ {
		go func(i int) {
			defer wg.Done()
			t.Run(fmt.Sprintf("LongLongLongLongName%d", i), func(t *testing.T) {})

On some invocations, I see something like:

=== RUN   Test/LongLongLongLongName48
=== RUN   Test/LongLon=== RUN   Test/LongLongLongLongName50
=== 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
Copy link

@gopherbot gopherbot commented Jan 24, 2017

CL 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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants