Description
What version of Go are you using (go version
)?
$ go version go version go1.21.3 linux/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 GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/rest/.cache/go-build' GOENV='/home/rest/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.21.3' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/dev/null' 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 -ffile-prefix-map=/tmp/go-build2287139495=/tmp/go-build -gno-record-gcc-switches'
What did you do?
We build a Go application which also include some CGO requests and very frequently we see SIGSEGV: segmentation violation
errors produced by an unwinding crash. Unfortunately, we are not able to reproduce the crash but the crashes occurred often without executing any specific request to produce this error. The crashes are happening frequently (more than 100 on a single day). We have checked the core dumps produced, but nothing there to indicate what causes the issue. Also, from core dumps, we see that there are no CGO requests during the time of the crash.
We see the following stacktrace
SIGSEGV: segmentation violation
PC=0x46df85 m=22 sigcode=1
goroutine 0 [idle]:
runtime.(*unwinder).next(0x7fa986bfc060)
runtime/traceback.go:463 +0x105 fp=0x7fa986bfbeb0 sp=0x7fa986bfbe38 pc=0x46df85
runtime.scanstack(0xc0013341a0, 0x100000081?)
runtime/mgcmark.go:802 +0x272 fp=0x7fa986bfc1e8 sp=0x7fa986bfbeb0 pc=0x42e392
runtime.markroot.func1()
runtime/mgcmark.go:240 +0xb5 fp=0x7fa986bfc238 sp=0x7fa986bfc1e8 pc=0x42d215
runtime.markroot(0xc00007a140, 0x3fe, 0x1)
runtime/mgcmark.go:214 +0x1a8 fp=0x7fa986bfc2e0 sp=0x7fa986bfc238 pc=0x42cea8
runtime.gcDrain(0xc00007a140, 0x7)
runtime/mgcmark.go:1069 +0x37d fp=0x7fa986bfc340 sp=0x7fa986bfc2e0 pc=0x42edfd
runtime.gcBgMarkWorker.func2()
runtime/mgc.go:1385 +0x6f fp=0x7fa986bfc390 sp=0x7fa986bfc340 pc=0x42b52f
traceback: unexpected SPWRITE function runtime.systemstack
runtime.systemstack()
runtime/asm_amd64.s:509 +0x4a fp=0x7fa986bfc3a0 sp=0x7fa986bfc390 pc=0x47bc4a
We also downgrade golang version to go1.21.0 linux/amd64
, but we see the same behaviour (same crashes), with a bit different stacktrace now.
SIGSEGV: segmentation violation
PC=0x46dea5 m=23 sigcode=1
goroutine 0 [idle]:
runtime.(*unwinder).next(0x7f89011f3060)
runtime/traceback.go:453 +0x105 fp=0x7f89011f2eb0 sp=0x7f89011f2e38 pc=0x46dea5
runtime.scanstack(0xc0031d44e0, 0x2a?)
runtime/mgcmark.go:802 +0x272 fp=0x7f89011f31e8 sp=0x7f89011f2eb0 pc=0x42e272
runtime.markroot.func1()
runtime/mgcmark.go:240 +0xb5 fp=0x7f89011f3238 sp=0x7f89011f31e8 pc=0x42d0f5
runtime.markroot(0xc00006e640, 0x1bb, 0x1)
runtime/mgcmark.go:214 +0x1a8 fp=0x7f89011f32e0 sp=0x7f89011f3238 pc=0x42cd88
runtime.gcDrain(0xc00006e640, 0x3)
runtime/mgcmark.go:1069 +0x37d fp=0x7f89011f3340 sp=0x7f89011f32e0 pc=0x42ecdd
runtime.gcBgMarkWorker.func2()
runtime/mgc.go:1366 +0xa5 fp=0x7f89011f3390 sp=0x7f89011f3340 pc=0x42b445
What did you expect to see?
No crashes
What did you see instead?
segmentation violation errors
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Activity
mauri870 commentedon Nov 9, 2023
I feel like
gp
orgp.m
might be nil here which is causing the segfault, given that we don't check for nillness in (*unwinder).nextgo/src/runtime/traceback.go
Line 463 in 883f062
If this issue is related to the new unwinder you could try go 1.20.10 that does not have it.
Would be helpful to get some more insights on what your program does with cgo, to try and reproduce the issue.
/cc @golang/runtime
prattmic commentedon Nov 9, 2023
I agree it would be interesting to know if the same crashes occur with the old unwinder. Thanks @mauri870.
Also, if you have a core dump, could you report what the values are of everything in
unwinder
? https://cs.opensource.google/go/go/+/master:src/runtime/traceback.go;drc=1cc19e5ba0a008df7baeb78e076e43f9d8e0abf2;bpv=1;bpt=1;l=94cherrymui commentedon Nov 9, 2023
Interesting. In both cases it is scanning a goroutine stack. If
gp
orgp.m
is nil, things would be very wrong...ihnorton commentedon Nov 9, 2023
Corresponding backtrace (different core dump than the initial report):
ihnorton commentedon Nov 9, 2023
The CGo usage is via the wrappers in this repository, (e.g.). Unfortunately, we don't have a reduced example yet.
We are currently testing the downgrade to 1.20.10 to see if that helps.
vser1 commentedon Nov 16, 2023
I encountered the exact same stack on go1.21.3 linux/amd64. I rolled back to go1.20.11 and got a similar segfault.
We might need to rollback to 1.19.5 which was our previous production version (from which we bumped to 1.21)
vser1 commentedon Jan 5, 2024
Also see #64781
cherrymui commentedon Jun 13, 2024
Is this still happening, with more recent version of Go? If so, could you share more information about the program, like, what stack does it scanning? Could you include a full crash log if possible? Thanks.
shaj13 commentedon Jun 24, 2024
@cherrymui
Our application occasionally throws this panic after upgrading to Go version 1.22 (specifically built with go1.22.1 linux/amd64). Here is a snippet of the panic message and the backtrace from Delve (dlv), let me know what other information is needed.
PANIC
2024-06-19T17:08:59.101284384Z SIGSEGV: segmentation violation 2024-06-19T17:08:59.101305416Z PC=0x468865 m=5 sigcode=1 addr=0x118 2024-06-19T17:08:59.101308921Z 2024-06-19T17:08:59.101313011Z goroutine 0 gp=0xc000103180 m=5 mp=0xc000100808 [idle]: 2024-06-19T17:08:59.101316543Z runtime.(*unwinder).next(0xc000157d28) 2024-06-19T17:08:59.101320330Z /usr/local/go/src/runtime/traceback.go:457 +0x105 fp=0xc000157ce8 sp=0xc000157c70 pc=0x468865 2024-06-19T17:08:59.101323626Z runtime.scanstack(0xc001225c00, 0xc000072168) 2024-06-19T17:08:59.101326778Z /usr/local/go/src/runtime/mgcmark.go:899 +0x271 fp=0xc000157e18 sp=0xc000157ce8 pc=0x423ed1 2024-06-19T17:08:59.101330416Z runtime.markroot.func1() 2024-06-19T17:08:59.101333574Z /usr/local/go/src/runtime/mgcmark.go:241 +0xb5 fp=0xc000157e68 sp=0xc000157e18 pc=0x422b95 2024-06-19T17:08:59.101336817Z runtime.markroot(0xc000072168, 0x3d6, 0x1) 2024-06-19T17:08:59.101340034Z /usr/local/go/src/runtime/mgcmark.go:215 +0x1a8 fp=0xc000157f10 sp=0xc000157e68 pc=0x422828 2024-06-19T17:08:59.101343201Z runtime.gcDrain(0xc000072168, 0x7) 2024-06-19T17:08:59.101346283Z /usr/local/go/src/runtime/mgcmark.go:1200 +0x3d4 fp=0xc000157f78 sp=0xc000157f10 pc=0x4249f4 2024-06-19T17:08:59.101349526Z runtime.gcDrainMarkWorkerIdle(...) 2024-06-19T17:08:59.101352636Z /usr/local/go/src/runtime/mgcmark.go:1114 2024-06-19T17:08:59.101355693Z runtime.gcBgMarkWorker.func2() 2024-06-19T17:08:59.101358906Z /usr/local/go/src/runtime/mgc.go:1406 +0x6f fp=0xc000157fc8 sp=0xc000157f78 pc=0x420e4f 2024-06-19T17:08:59.101362075Z runtime.systemstack(0x0) 2024-06-19T17:08:59.101365136Z /usr/local/go/src/runtime/asm_amd64.s:509 +0x4a fp=0xc000157fd8 sp=0xc000157fc8 pc=0x475e8a
BT
P U
LIST
12 remaining items