Skip to content

testing: racey access to t.failed #24438

@nhooyr

Description

@nhooyr

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nhooyr/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nhooyr/Programming/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7b/218sfv615xxf_w9ttnpjt0_r0000gn/T/go-build699377598=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package foo

import "testing"

func TestBar(t *testing.T) {
	go func() {
		t.Error("meow")
	}()
}

Run with the race detector.

What did you expect to see?

No race condition.

What did you see instead?

Race condition.

==================
WARNING: DATA RACE
Write at 0x00c4200ca131 by goroutine 7:
  testing.(*common).Fail()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:511 +0xb2
  testing.(*common).Error()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:579 +0x7c
  command-line-arguments.TestBar.func1()
      /Users/nhooyr/Library/Preferences/GoLand2017.3/scratches/scratch_59_test.go:7 +0x88

Previous read at 0x00c4200ca131 by goroutine 6:
  testing.tRunner()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:779 +0x17f

Goroutine 7 (running) created at:
  command-line-arguments.TestBar()
      /Users/nhooyr/Library/Preferences/GoLand2017.3/scratches/scratch_59_test.go:6 +0x4c
  testing.tRunner()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:777 +0x16d

Goroutine 6 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:824 +0x564
  testing.runTests.func1()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:1063 +0xa4
  testing.tRunner()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:777 +0x16d
  testing.runTests()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:1061 +0x4e1
  testing.(*M).Run()
      /usr/local/Cellar/go/1.10/libexec/src/testing/testing.go:978 +0x2cd
  main.main()
      _testmain.go:42 +0x22a
==================
--- FAIL: TestBar (0.00s)
	scratch_59_test.go:7: meow
FAIL
FAIL	command-line-arguments	0.012s

Reason is that the variable read at

if t.failed {
needs to be done while t.mu is rlocked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions