DEV Community

Cover image for Fix Unexpected Signal During Runtime Execution Go 1.17
Muhammad Ilham hidayat
Muhammad Ilham hidayat

Posted on

Fix Unexpected Signal During Runtime Execution Go 1.17

Recently, when I ran Go code with version 1.17 on macOS Big Sur 11.6, I got this fatal error response 🥴

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x7fff204acc9e]

runtime stack:
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff204acc9e
stack: frame={sp:0x7ffeefbff578, fp:0x7ffeefbff5c8} stack=[0x7ffeefb80618,0x7ffeefbff680)
0x00007ffeefbff478:  0x01007ffeefbff498  0x0000000000000004
0x00007ffeefbff488:  0x000000000000001f  0x00007fff204acc9e
0x00007ffeefbff498:  0x0b01dfacedebac1e  0x0000000000000001
0x00007ffeefbff4a8:  0x00000000040362f1 <runtime.throw+0x0000000000000071>  0x00007ffeefbff548
0x00007ffeefbff4b8:  0x00000000049112ab  0x00007ffeefbff500
0x00007ffeefbff4c8:  0x00000000040365a8 <runtime.fatalthrow.func1+0x0000000000000048>  0x0000000004f41400
........
exit status 2
// https://gist.github.com/milhamh95/ff194322cecd6ba56573b2eddaecf13a
Enter fullscreen mode Exit fullscreen mode

When I searched through the stack trace, I completely didn’t understand what is the error and the solution 😐.

Luckily, I found the same issue at Go Github issues.

runtime: unexpected signal during runtime execution in Go 1.17 but not Go 1.16 #46763

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

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

Does this issue reproduce with the latest release?

Yes for 1.17 no for latest stable release (1.16)

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/marwansulaiman/Library/Caches/go-build"
GOENV="/Users/marwansulaiman/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/marwansulaiman/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="marwan.io/*,github.com/marwan-at-work/*,github.com/github/*"
GOOS="darwin"
GOPATH="/Users/marwansulaiman/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/marwansulaiman/marwan/gorme/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j7/fhzzr84926x491hwp37ltv_r0000gn/T/go-build1384886840=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

The steps are quite reproducible:

  1. Install go1.17 beta for mac.
  2. Run the following commands:
$ mkdir gorme && cd ./gorme
$ go mod init gorme
go: creating new go.mod: module gorme
$ go get github.com/sirupsen/logrus
go get: added github.com/sirupsen/logrus v1.8.1
$ go get github.com/lightstep/lightstep-tracer-go
go get: added github.com/lightstep/lightstep-tracer-go v0.25.0

Add the following main.go file:

package main

import "github.com/sirupsen/logrus"

import (
    _ "github.com/lightstep/lightstep-tracer-go"
)

func main() {
    l := logrus.New()
    l.Info("hello")
}
Enter fullscreen mode Exit fullscreen mode
$ go mod tidy
$ go run -trimpath .
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x7fff6d88a70a]

runtime stack:
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff6d88a70a
stack: frame={sp:0x7ffeefbff228, fp:0x7ffeefbff278} stack=[0x7ffeefb802c8,0x7ffeefbff330)
0x00007ffeefbff128:  0x01007ffeefbff148  0x0000000000000004 
0x00007ffeefbff138:  0x000000000000001f  0x00007fff6d88a70a 
0x00007ffeefbff148:  0x0b01dfacedebac1e  0x0000000000000001 
0x00007ffeefbff158:  0x0000000004034951 <runtime.throw+0x0000000000000071>  0x00007ffeefbff1f8 
0x00007ffeefbff168:  0x000000000445e6de  0x00007ffeefbff1b0 
0x00007ffeefbff178:  0x0000000004034c08 <runtime.fatalthrow.func1+0x0000000000000048>  0x00000000047c4d40 
0x00007ffeefbff188:  0x0000000000000001  0x0000000000000001 
0x00007ffeefbff198:  0x00007ffeefbff1f8  0x0000000004034951 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff1a8:  0x00000000047c4d40  0x00007ffeefbff1e8 
0x00007ffeefbff1b8:  0x0000000004034b90 <runtime.fatalthrow+0x0000000000000050>  0x00007ffeefbff1c8 
0x00007ffeefbff1c8:  0x0000000004034bc0 <runtime.fatalthrow.func1+0x0000000000000000>  0x00000000047c4d40 
0x00007ffeefbff1d8:  0x0000000004034951 <runtime.throw+0x0000000000000071>  0x00007ffeefbff1f8 
0x00007ffeefbff1e8:  0x00007ffeefbff218  0x0000000004034951 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff1f8:  0x00007ffeefbff200  0x0000000004034980 <runtime.throw.func1+0x0000000000000000> 
0x00007ffeefbff208:  0x00000000044649ef  0x000000000000002a 
0x00007ffeefbff218:  0x00007ffeefbff268  0x0000000004049f36 <runtime.sigpanic+0x0000000000000396> 
0x00007ffeefbff228: <0x00000000044649ef  0x0000000000000000 
0x00007ffeefbff238:  0x00007ffeefbff2a8  0x0000000004027866 <runtime.(*mheap).allocSpan+0x0000000000000546> 
0x00007ffeefbff248:  0x000000c00023a000  0x0000000000004000 
0x00007ffeefbff258:  0x00007fff00000008  0x000000c0001b0000 
0x00007ffeefbff268:  0x00007ffeefbff2b0 !0x00007fff6d88a70a 
0x00007ffeefbff278: >0x00007ffeefbff2b0  0x0000000004760000 
0x00007ffeefbff288:  0x000000000000043d  0x0000000004101185 <golang.org/x/sys/unix.libc_ioctl_trampoline+0x0000000000000005> 
0x00007ffeefbff298:  0x0000000004065d9f <runtime.syscall+0x000000000000001f>  0x000000c0001af640 
0x00007ffeefbff2a8:  0x000000000406570c <runtime.nanotime_trampoline+0x000000000000000c>  0x000000c0001af610 
0x00007ffeefbff2b8:  0x0000000004063c10 <runtime.asmcgocall+0x0000000000000070>  0x0000000000000002 
0x00007ffeefbff2c8:  0x0000000004005d00 <runtime.cgoCheckWriteBarrier+0x0000000000000020>  0x5d00000000001018 
0x00007ffeefbff2d8:  0x0000000000000000  0x00000000047f7a58 
0x00007ffeefbff2e8:  0x0000000000000a18  0x000000c0000001a0 
0x00007ffeefbff2f8:  0x0000000004061d29 <runtime.systemstack+0x0000000000000049>  0x0000000000000004 
0x00007ffeefbff308:  0x00000000044d2170  0x00000000047c4d40 
0x00007ffeefbff318:  0x00007ffeefbff368  0x0000000004061c25 <runtime.mstart+0x0000000000000005> 
0x00007ffeefbff328:  0x0000000004061bdd <runtime.rt0_go+0x000000000000013d> 
runtime.throw({0x44649ef, 0x0})
        runtime/panic.go:1198 +0x71
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff6d88a70a
stack: frame={sp:0x7ffeefbff228, fp:0x7ffeefbff278} stack=[0x7ffeefb802c8,0x7ffeefbff330)
0x00007ffeefbff128:  0x01007ffeefbff148  0x0000000000000004 
0x00007ffeefbff138:  0x000000000000001f  0x00007fff6d88a70a 
0x00007ffeefbff148:  0x0b01dfacedebac1e  0x0000000000000001 
0x00007ffeefbff158:  0x0000000004034951 <runtime.throw+0x0000000000000071>  0x00007ffeefbff1f8 
0x00007ffeefbff168:  0x000000000445e6de  0x00007ffeefbff1b0 
0x00007ffeefbff178:  0x0000000004034c08 <runtime.fatalthrow.func1+0x0000000000000048>  0x00000000047c4d40 
0x00007ffeefbff188:  0x0000000000000001  0x0000000000000001 
0x00007ffeefbff198:  0x00007ffeefbff1f8  0x0000000004034951 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff1a8:  0x00000000047c4d40  0x00007ffeefbff1e8 
0x00007ffeefbff1b8:  0x0000000004034b90 <runtime.fatalthrow+0x0000000000000050>  0x00007ffeefbff1c8 
0x00007ffeefbff1c8:  0x0000000004034bc0 <runtime.fatalthrow.func1+0x0000000000000000>  0x00000000047c4d40 
0x00007ffeefbff1d8:  0x0000000004034951 <runtime.throw+0x0000000000000071>  0x00007ffeefbff1f8 
0x00007ffeefbff1e8:  0x00007ffeefbff218  0x0000000004034951 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff1f8:  0x00007ffeefbff200  0x0000000004034980 <runtime.throw.func1+0x0000000000000000> 
0x00007ffeefbff208:  0x00000000044649ef  0x000000000000002a 
0x00007ffeefbff218:  0x00007ffeefbff268  0x0000000004049f36 <runtime.sigpanic+0x0000000000000396> 
0x00007ffeefbff228: <0x00000000044649ef  0x0000000000000000 
0x00007ffeefbff238:  0x00007ffeefbff2a8  0x0000000004027866 <runtime.(*mheap).allocSpan+0x0000000000000546> 
0x00007ffeefbff248:  0x000000c00023a000  0x0000000000004000 
0x00007ffeefbff258:  0x00007fff00000008  0x000000c0001b0000 
0x00007ffeefbff268:  0x00007ffeefbff2b0 !0x00007fff6d88a70a 
0x00007ffeefbff278: >0x00007ffeefbff2b0  0x0000000004760000 
0x00007ffeefbff288:  0x000000000000043d  0x0000000004101185 <golang.org/x/sys/unix.libc_ioctl_trampoline+0x0000000000000005> 
0x00007ffeefbff298:  0x0000000004065d9f <runtime.syscall+0x000000000000001f>  0x000000c0001af640 
0x00007ffeefbff2a8:  0x000000000406570c <runtime.nanotime_trampoline+0x000000000000000c>  0x000000c0001af610 
0x00007ffeefbff2b8:  0x0000000004063c10 <runtime.asmcgocall+0x0000000000000070>  0x0000000000000002 
0x00007ffeefbff2c8:  0x0000000004005d00 <runtime.cgoCheckWriteBarrier+0x0000000000000020>  0x5d00000000001018 
0x00007ffeefbff2d8:  0x0000000000000000  0x00000000047f7a58 
0x00007ffeefbff2e8:  0x0000000000000a18  0x000000c0000001a0 
0x00007ffeefbff2f8:  0x0000000004061d29 <runtime.systemstack+0x0000000000000049>  0x0000000000000004 
0x00007ffeefbff308:  0x00000000044d2170  0x00000000047c4d40 
0x00007ffeefbff318:  0x00007ffeefbff368  0x0000000004061c25 <runtime.mstart+0x0000000000000005> 
0x00007ffeefbff328:  0x0000000004061bdd <runtime.rt0_go+0x000000000000013d> 
runtime.sigpanic()
        runtime/signal_unix.go:719 +0x396

goroutine 1 [syscall]:
syscall.syscall(0x4101180, 0x2, 0x40487413, 0xc0001af6d0)
        runtime/sys_darwin.go:22 +0x3b fp=0xc0001af640 sp=0xc0001af620 pc=0x40609bb
syscall.syscall(0x90f0f67d3201c856, 0x7de8cfa85ade3600, 0xb9d8eea6e34af808, 0xd822576cb22b7f61)
        <autogenerated>:1 +0x26 fp=0xc0001af688 sp=0xc0001af640 pc=0x4066566
golang.org/x/sys/unix.ioctl(0x3530ae4f63bfad50, 0x786493e590fecfac, 0x2154961679b0d)
        golang.org/x/sys@v0.0.0-20210217105451-b926d437f341/unix/zsyscall_darwin_amd64.go:689 +0x39 fp=0xc0001af6b8 sp=0xc0001af688 pc=0x4100a39
golang.org/x/sys/unix.IoctlGetTermios(...)
        golang.org/x/sys@v0.0.0-20210217105451-b926d437f341/unix/ioctl.go:72
github.com/sirupsen/logrus.isTerminal(0x87296cca2bde7aa)
        github.com/sirupsen/logrus@v1.8.1/terminal_check_bsd.go:11 +0x50 fp=0xc0001af728 sp=0xc0001af6b8 pc=0x410af30
github.com/sirupsen/logrus.checkIfTerminal({0x44d6820, 0xc000198010})
        github.com/sirupsen/logrus@v1.8.1/terminal_check_notappengine.go:13 +0x75 fp=0xc0001af740 sp=0xc0001af728 pc=0x410afd5
github.com/sirupsen/logrus.(*TextFormatter).init(0xc00019a6c0, 0x8)
        github.com/sirupsen/logrus@v1.8.1/text_formatter.go:106 +0x34 fp=0xc0001af7c0 sp=0xc0001af740 pc=0x410b0b4
github.com/sirupsen/logrus.(*TextFormatter).Format.func1()
        github.com/sirupsen/logrus@v1.8.1/text_formatter.go:196 +0x25 fp=0xc0001af7e0 sp=0xc0001af7c0 pc=0x410c765
sync.(*Once).doSlow(0x44deab0, 0xc0001901c8)
        sync/once.go:68 +0xd2 fp=0xc0001af848 sp=0xc0001af7e0 pc=0x4078312
sync.(*Once).Do(...)
        sync/once.go:59
github.com/sirupsen/logrus.(*TextFormatter).Format(0xc00019a6c0, 0xc00021a1c0)
        github.com/sirupsen/logrus@v1.8.1/text_formatter.go:196 +0xebe fp=0xc0001afdb8 sp=0xc0001af848 pc=0x410c11e
github.com/sirupsen/logrus.(*Entry).write(0xc00021a1c0)
        github.com/sirupsen/logrus@v1.8.1/entry.go:279 +0x56 fp=0xc0001afe48 sp=0xc0001afdb8 pc=0x41063f6
github.com/sirupsen/logrus.(*Entry).log(0xc0001aff60, 0x4, {0xc00019c930, 0x5})
        github.com/sirupsen/logrus@v1.8.1/entry.go:251 +0x219 fp=0xc0001afeb8 sp=0xc0001afe48 pc=0x4105ff9
github.com/sirupsen/logrus.(*Entry).Log(0xc00021a150, 0x4, {0xc0001aff60, 0x70, 0x4431420})
        github.com/sirupsen/logrus@v1.8.1/entry.go:293 +0x4f fp=0xc0001afee8 sp=0xc0001afeb8 pc=0x410664f
github.com/sirupsen/logrus.(*Logger).Log(0xc00021a0e0, 0x4, {0xc0001aff60, 0x1, 0x1})
        github.com/sirupsen/logrus@v1.8.1/logger.go:198 +0x65 fp=0xc0001aff28 sp=0xc0001afee8 pc=0x4109265
github.com/sirupsen/logrus.(*Logger).Info(...)
        github.com/sirupsen/logrus@v1.8.1/logger.go:220
main.main()
        gorme/main.go:11 +0xfe fp=0xc0001aff80 sp=0xc0001aff28 pc=0x43946be
runtime.main()
        runtime/proc.go:255 +0x227 fp=0xc0001affe0 sp=0xc0001aff80 pc=0x4036fe7
runtime.goexit()
        runtime/asm_amd64.s

What did you expect to see?

In Go 1.16 things work fine:

$ docker run --rm -it -v `pwd`:/app golang:1.16
root@0341e88de5ea:/go# cd /app
root@0341e88de5ea:/app# go run -trimpath .
go: downloading github.com/sirupsen/logrus v1.8.1
go: downloading github.com/lightstep/lightstep-tracer-go v0.25.0
go: downloading golang.org/x/sys v0.0.0-20210217105451-b926d437f341
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20210210170715-a8dfcb80d3a7
go: downloading github.com/opentracing/opentracing-go v1.0.2
go: downloading google.golang.org/grpc v1.21.0
go: downloading github.com/shirou/gopsutil/v3 v3.21.2
go: downloading golang.org/x/net v0.0.0-20201021035429-f5854403a974
go: downloading google.golang.org/genproto v0.0.0-20190530194941-fb225487d101
go: downloading github.com/tklauser/go-sysconf v0.3.4
go: downloading github.com/golang/protobuf v1.3.1
go: downloading github.com/tklauser/numcpus v0.2.1
go: downloading golang.org/x/text v0.3.3
INFO[0000] hello   

What did you see instead?

The segment violation mentioned above.

Note that only when I added the lightstep tracer above did the runtime panic occur. It is probably due to enforcement of an underlying dependency namely golang.org/x/sys.

If I upgrade the underlying dependency (though I've never directly used it), it actually ends up working. To be specific:

This works: golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 This does not work: golang.org/x/sys v0.0.0-20210217105451-b926d437f341 // indirect

However, in 1.16, both work fine. Which is why I think this is more of a Go bug rather than a library bug.

Thanks!

Comment for #45702

@cherrymui yes, I was mistakenly attempting to update x/sys in GOROOT.

After running go get golang.org/x/sys@master, I am able to successfully run my tests without any unexpected return pc errors, using go version devel go1.17-af6123a865 Fri May 7 18:14:25 2021 +0000 darwin/amd64.

Thanks again!

Based on those Github issues, to fix unexpected signal during runtime execution I need to update Go Sys package to the latest version in every my Go repo project.

go get golang.org/x/sys@master
Enter fullscreen mode Exit fullscreen mode

Go Sys Package

After updating Golang Sys package, I can ran my code without any issues 👍.

Discussion (0)