Skip to content

cmd/compile/internal: DATA RACE if -coverprofile flag is provided #56370

@olegbespalov

Description

@olegbespalov

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

$  gotip version
go version devel go1.20-c75b10b Fri Oct 21 05:28:30 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

Not from my experience

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

go env Output
$ gotip env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/olegbespalov/.cache/go-build"
GOENV="/home/olegbespalov/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/olegbespalov/go/pkg/mod"
GOOS="linux"
GOPATH="/home/olegbespalov/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/olegbespalov/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/olegbespalov/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.20-c75b10b Fri Oct 21 05:28:30 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/olegbespalov/projects/sandbox/go/race/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build352388576=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run

gotip test --count=1 -race -coverprofile=/tmp/code-coverage.out ./...

On the package that filter

filter.go

package filter

func New() func(error) bool {
	return func(error) bool {
		return false
	}
}

filter_test.go

package filter_test

import (
	"testing"

	"github.com/olegbespalov/race/filter"
)

func Test1(t *testing.T) {
	t.Parallel()

	_ = filter.New()
}

func Test2(t *testing.T) {
	t.Parallel()

	_ = filter.New()
}

func Test3(t *testing.T) {
	t.Parallel()

	_ = filter.New()
}

func Test4(t *testing.T) {
	t.Parallel()

	_ = filter.New()
}

My go.mod, just in case

module github.com/olegbespalov/race

go 1.19

What did you expect to see?

No data races

What did you see instead?

A race was detected.

race trace stack
==================
WARNING: DATA RACE
Write at 0x000001692fe0 by goroutine 8:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x50
  github.com/olegbespalov/race/filter_test.Test2()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:18 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Previous write at 0x000001692fe0 by goroutine 7:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x50
  github.com/olegbespalov/race/filter_test.Test1()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:12 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Goroutine 8 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc

Goroutine 7 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc
==================
==================
WARNING: DATA RACE
Write at 0x000001692fe0 by goroutine 9:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x50
  github.com/olegbespalov/race/filter_test.Test3()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:24 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Previous write at 0x000001692fe0 by goroutine 10:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x50
  github.com/olegbespalov/race/filter_test.Test4()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:30 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Goroutine 9 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc

Goroutine 10 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc
==================
==================
WARNING: DATA RACE
Write at 0x000001692fe4 by goroutine 9:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x7c
  github.com/olegbespalov/race/filter_test.Test3()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:24 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Previous write at 0x000001692fe4 by goroutine 8:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x7c
  github.com/olegbespalov/race/filter_test.Test2()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:18 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Goroutine 9 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc

Goroutine 8 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc
==================
==================
WARNING: DATA RACE
Write at 0x000001692fe8 by goroutine 8:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x92
  github.com/olegbespalov/race/filter_test.Test2()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:18 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Previous write at 0x000001692fe8 by goroutine 10:
  github.com/olegbespalov/race/filter.New()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter.go:3 +0x92
  github.com/olegbespalov/race/filter_test.Test4()
      /home/olegbespalov/projects/sandbox/go/race/filter/filter_test.go:30 +0x31
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.(*T).Run.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x47

Goroutine 8 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc

Goroutine 10 (running) created at:
  testing.(*T).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1548 +0x75d
  testing.runTests.func1()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1913 +0x72
  testing.tRunner()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1501 +0x216
  testing.runTests()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1911 +0x884
  testing.(*M).Run()
      /home/olegbespalov/sdk/gotip/src/testing/testing.go:1783 +0xa84
  main.main()
      _testmain.go:86 +0x2fc
==================
--- FAIL: Test1 (0.00s)
--- FAIL: Test2 (0.00s)
    testing.go:1374: race detected during execution of test
--- FAIL: Test3 (0.00s)
    testing.go:1374: race detected during execution of test
--- FAIL: Test4 (0.00s)
    testing.go:1374: race detected during execution of test
FAIL
	github.com/olegbespalov/race/filter	coverage: 50.0% of statements
FAIL	github.com/olegbespalov/race/filter	0.011s
FAIL

So this is around for a week or so in our CI. I tried to git bisect, and it showed me that this commit 4a459cb is the one where it started, but maybe I'm wrong here 🤷

If I run the go test without -coverprofile flag, no data race appears.

$ gotip test --count=1 -race ./...
ok      github.com/olegbespalov/race/filter     0.021s

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions