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: FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc on go1.12beta1/tip #29329

Closed
paulmach opened this issue Dec 19, 2018 · 5 comments

Comments

@paulmach
Copy link

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

$ go version
go version go1.12beta1 darwin/amd64

Does this issue reproduce with the latest release?

I have reproduced on "tip" on travis-ci (1, 2, 3) and locally (osx) using go1.12beta1 installed via gvm

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pamach/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/pamach/.gvm/pkgsets/go1.12beta1/global"
GOPROXY=""
GORACE=""
GOROOT="/Users/pamach/.gvm/gos/go1.12beta1"
GOTMPDIR=""
GOTOOLDIR="/Users/pamach/.gvm/gos/go1.12beta1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/jb/mt5nv3rd4p78_3k9gr__gkym0000gp/T/go-build498123624=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. installed gvm to get a post g1.11 build.
  2. gvm install go1.12beta1
  3. gvm use go1.12beta1
  4. go get github.com/paulmach/orb
  5. cd $GOPATH/src/github.com/paulmach/orb/simplify
  6. go test -race -v .

What did you expect to see?

PASS
ok  	github.com/paulmach/orb/simplify	0.430s

What did you see instead?

=== RUN   TestDouglasPeucker_BenchmarkData
--- PASS: TestDouglasPeucker_BenchmarkData (0.73s)
FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc:6826 "((kBlockMagic)) == ((((u64*)addr)[0]))" (0x6a6cb03abcebc041, 0x109907e)
FAIL	github.com/paulmach/orb/simplify	0.752s
@ianlancetaylor ianlancetaylor added RaceDetector NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Dec 19, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Dec 19, 2018
@ianlancetaylor ianlancetaylor changed the title FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc on go1.12beta1/tip runtime/race: FATAL: ThreadSanitizer CHECK failed: ./gotsan.cc on go1.12beta1/tip Dec 19, 2018
@ianlancetaylor
Copy link
Contributor

CC @dvyukov

@ianlancetaylor
Copy link
Contributor

This appears to be due to an assertion failure in InternalFree in compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc.

  CHECK_EQ(kBlockMagic, ((u64*)addr)[0]);

That suggests that memory corruption is occurring somewhere.

@ianlancetaylor
Copy link
Contributor

Actually this appears to be a compiler error. It is compiling a method such that it calls racefuncexit but not racefuncenter.

@ianlancetaylor
Copy link
Contributor

CC @randall77

Here is a standalone reproducer. It doesn't crash in the same way, but it does crash with tip. With 1.11 it succeeds. The bug is that main.(*DouglasPeuckerSimplifier).LineString calls runtime.racefuncexit but never calls runtime.racefuncenter. That method inlines a couple of functions, so this may be a bug in mid-stack inlining.

package main

import (
	"fmt"
)


type LineString []Point
type Point [2]float64

//go:noinline
func benchmarkData() LineString {
	return LineString{{1.0, 2.0}}
}

func (ls LineString) Clone() LineString {
	ps := MultiPoint(ls)
	return LineString(ps.Clone())
}

type MultiPoint []Point

func (mp MultiPoint) Clone() MultiPoint {
	if mp == nil {
		return nil
	}

	points := make([]Point, len(mp))
	copy(points, mp)

	return MultiPoint(points)
}

func F1() {
	cases := []struct {
		threshold float64
		length    int
	}{
		{0.1, 1118},
		{0.5, 257},
		{1.0, 144},
		{1.5, 95},
		{2.0, 71},
		{3.0, 46},
		{4.0, 39},
		{5.0, 33},
	}

	ls := benchmarkData()

	for k := 0; k < 100; k++ {
		for i, tc := range cases {
			r := DouglasPeucker(tc.threshold).LineString(ls.Clone())
			if len(r) == tc.length {
				fmt.Printf("%d: unexpected\n", i)
			}
		}
	}
}

// A DouglasPeuckerSimplifier wraps the DouglasPeucker function.
type DouglasPeuckerSimplifier struct {
	Threshold float64
}

// DouglasPeucker creates a new DouglasPeuckerSimplifier.
func DouglasPeucker(threshold float64) *DouglasPeuckerSimplifier {
	return &DouglasPeuckerSimplifier{
		Threshold: threshold,
	}
}

func (s *DouglasPeuckerSimplifier) LineString(ls LineString) LineString {
	return lineString(s, ls)
}

type simplifier interface {
	simplify(LineString, bool) (LineString, []int)
}

func lineString(s simplifier, ls LineString) LineString {
	return runSimplify(s, ls)
}

func runSimplify(s simplifier, ls LineString) LineString {
	if len(ls) <= 2 {
		return ls
	}
	ls, _ = s.simplify(ls, false)
	return ls
}

func (s *DouglasPeuckerSimplifier) simplify(ls LineString, wim bool) (LineString, []int) {
	return nil, nil
}

func main() {
	F1()
}

@gopherbot
Copy link

Change https://golang.org/cl/155917 mentions this issue: cmd/compile: fix racewalk{enter,exit} removal

@randall77 randall77 self-assigned this Dec 28, 2018
@randall77 randall77 removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 28, 2018
@golang golang locked and limited conversation to collaborators Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants