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

reflect: fatal error: reflect mismatch when reflect.MakeFunc is used as a goroutine #25897

Open
liulk opened this Issue Jun 14, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@liulk
Copy link

liulk commented Jun 14, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="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=/tmp/go-build622183756=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have a function consume() made by reflect.MakeFunc(). When I run it as a goroutine go consume(...), if it coincides with a GC cycle, the program dies with the following error:

runtime: confused by reflect.makeFuncStub
fatal error: reflect mismatch
...
runtime stack:
...
goroutine 166 [runnable (scan)]:
reflect.makeFuncStub(0xc42001e0c0, 0xc420014140, 0x0, 0x0, 0x0, 0x0, 0xc42013e800, 0x0, 0x0, 0x0, ...)
        /usr/lib/google-golang/src/reflect/asm_amd64.s:12
created by main.runConsume
        /usr/local/google/home/liulk/tmp/test-go/reflectmismatch.go:52 +0x7e

Each time the fatal error happens, the goroutine with runnable (scan) status is always in reflect.makeFuncStub(). However, if I wrap the goroutine under a func() closure like go func() { consume(...) }() then the problem goes away.

Here is a playground link showing that this issue is reproducible in the playground: https://play.golang.org/p/vDyOEMZoAWf

There is a previous issue also mentioning reflect mismatch, but I think that's a different issue that is already fixed: #18635

What did you expect to see?

The program should run until completion.

What did you see instead?

The program crashed with "fatal error: reflect mismatch"

@bradfitz bradfitz added the NeedsFix label Jun 14, 2018

@bradfitz bradfitz added this to the Go1.11 milestone Jun 14, 2018

@bradfitz

This comment has been minimized.

Copy link
Member

bradfitz commented Jun 14, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Jun 14, 2018

Works in Go 1.3, fails in every version since. Works with gccgo. Easy to work around. Setting milestone to 1.12.

@ianlancetaylor ianlancetaylor changed the title fatal error: reflect mismatch when reflect.MakeFunc is used as a goroutine reflect: fatal error: reflect mismatch when reflect.MakeFunc is used as a goroutine Jun 14, 2018

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 14, 2018

@andybons andybons modified the milestones: Go1.12, Go1.13 Feb 12, 2019

@odeke-em

This comment has been minimized.

Copy link
Member

odeke-em commented Mar 12, 2019

Kindly paging also @randall77

@josharian

This comment has been minimized.

Copy link
Contributor

josharian commented Mar 12, 2019

The easy, shallow fix for this is probably to teach the compiler to do the “wrap in a closure” trick itself. It already does that for a print and some other builtins; this probably just requires adding a special case for (say) any calls in package reflect. Might be a decent starter issue for someone working on the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.