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

runtime/race: panic+recover in init() adds extra info to data race stack traces in main() #46095

Open
mattfedd opened this issue May 11, 2021 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. RaceDetector
Milestone

Comments

@mattfedd
Copy link

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

$ go version
go version go1.16.4 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Matthew\AppData\Local\go-build
set GOENV=C:\Users\Matthew\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Matthew\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Matthew\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.4
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=F:\Documents\Github\temp\go-test\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Matthew\AppData\Local\Temp\go-build309976296=/tmp/go-build -gno-record-gcc-switches

What did you do?

Ran the following program with go run -race main.go

package main

import (
	"fmt"
)

func init() {
	// call multiple times to exaggerate issue
	A()
	A()
	A()
	A()
}

func A() {
	defer func() {
		if e := recover(); e != nil {
			fmt.Println(e)
		}
	}()
	fmt.Println("A")
	B()
}

func B() {
	// this level of separation between the panic call and the recover call appears to be important.
	// If panic/recover happens within the same function, or within 1 call stack, nothing looks weird in the output data race
	fmt.Println("B")
	C()
}

func C() {
	fmt.Println("C")
	panic("panicking")
}

func main() {
	a := 0
	b := 0
	go func() {
		b = 1
	}()

	go func() {
		a = b
	}()
}

What did you expect to see?

I expect a detected data race in main() to not contain stack trace information from init().

> go run -race main.go
A
B
C
panicking
A
B
C
panicking
A
B
C
panicking
A
B
C
panicking
==================
WARNING: DATA RACE
Read at 0x00c00012e0e0 by goroutine 8:
  main.main.func2()
      F:/Documents/Github/temp/go-test/main.go:45 +0x44

Previous write at 0x00c00012e0e0 by goroutine 7:
  main.main.func1()
      F:/Documents/Github/temp/go-test/main.go:41 +0x44

Goroutine 8 (running) created at:
  main.main()
      F:/Documents/Github/temp/go-test/main.go:44 +0xdc

Goroutine 7 (finished) created at:
  main.main()
      F:/Documents/Github/temp/go-test/main.go:40 +0xb0
==================
Found 1 data race(s)
exit status 66

What did you see instead?

> go run -race main.go
A
B
C
panicking
A
B
C
panicking
A
B
C
panicking
A
B
C
panicking
==================
WARNING: DATA RACE
Read at 0x00c00012e128 by goroutine 8:
  main.main.func2()
      F:/Documents/Github/temp/go-test/main.go:45 +0x44

Previous write at 0x00c00012e128 by goroutine 7:
  main.main.func1()
      F:/Documents/Github/temp/go-test/main.go:41 +0x44

Goroutine 8 (running) created at:
  main.main()
      F:/Documents/Github/temp/go-test/main.go:44 +0xdc
  runtime.main()
      C:/Program Files/Go/src/runtime/proc.go:225 +0x255
  main.init.0()
      F:/Documents/Github/temp/go-test/main.go:11 +0x44
  main.init.0()
      F:/Documents/Github/temp/go-test/main.go:10 +0x3b
  main.init.0()
      F:/Documents/Github/temp/go-test/main.go:9 +0x36

Goroutine 7 (finished) created at:
  main.main()
      F:/Documents/Github/temp/go-test/main.go:40 +0xb0
  runtime.main()
      C:/Program Files/Go/src/runtime/proc.go:225 +0x255
  main.init.0()
      F:/Documents/Github/temp/go-test/main.go:11 +0x44
  main.init.0()
      F:/Documents/Github/temp/go-test/main.go:10 +0x3b
  main.init.0()
      F:/Documents/Github/temp/go-test/main.go:9 +0x36
==================
Found 1 data race(s)
exit status 66
@heschi heschi added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 11, 2021
@heschi heschi added this to the Backlog milestone May 11, 2021
@heschi heschi changed the title runtime: panic+recover in init() adds extra info to data race stack traces in main() runtime/race: panic+recover in init() adds extra info to data race stack traces in main() May 11, 2021
@heschi
Copy link
Contributor

heschi commented May 11, 2021

cc @dvyukov

@dvyukov
Copy link
Member

dvyukov commented May 11, 2021

It looks like a dup of #26813

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. RaceDetector
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants