golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.72k stars 17.63k forks source link

cgo panic SIGSEGV #43977

Closed tgulacsi closed 3 years ago

tgulacsi commented 3 years ago

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

1.16.rc1, gotip

$ go version
go version devel +c8bd801 Thu Jan 28 16:45:43 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

dev c8bd801

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/gthomas/bin"
GOCACHE="/home/gthomas/.cache/go-build"
GOENV="/home/gthomas/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/gthomas/go/pkg/mod"
GONOPROXY="unosoft.hu"
GONOSUMDB="unosoft.hu"
GOOS="linux"
GOPATH="/home/gthomas/go"
GOPRIVATE="unosoft.hu"
GOPROXY="http://proxy.golang.org,direct"
GOROOT="/home/gthomas/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/gthomas/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +c8bd801 Thu Jan 28 16:45:43 2021 +0000"
GCCGO="/usr/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2092844374=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run go test for github.com/godror/godor v0.23.2

What did you expect to see?

The test runs successfully.

What did you see instead?

$ gotip test
Using default database for tests:  /home/gthomas/src/github.com/godror/godror/contrib/free.db/env.sh
export TNS_ADMIN="/home/gthomas/src/github.com/godror/godror/contrib/free.db"
export "GODROR_TEST_USERNAME"="test"
export "GODROR_TEST_PASSWORD"="r97oUPimsmTOIcBaeeDF"
export "GODROR_TEST_DB"="db201911301540_high"
export "GODROR_TEST_STANDALONE"="1"
# user=test password="SECRET-lc79Key-hlk=" connectString=db201911301540_high
configDir=/tmp/godror_drv_test-854751408 connectionClass=TestClassName enableEvents=1
heterogeneousPool=0 libDir= poolIncrement=2 poolMaxSessions=16 poolMinSessions=2
poolSessionMaxLifetime=5m0s poolSessionTimeout=1m0s poolWaitTimeout=5s prelim=0
standaloneConnection=1 sysasm=0 sysdba=0 sysoper=0 timezone=local
Version: v0.23.2
Client: 21.1.0.0.0 Timezone: Local
Server: 19.5.0.0.0 [Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production; Version 19.5.0.0.0] Timezone: UTC
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xba0 pc=0x6e662a]

runtime stack:
runtime.throw(0x7aa0cd, 0x2a)
        /home/gthomas/sdk/gotip/src/runtime/panic.go:1117 +0x72
runtime.sigpanic()
        /home/gthomas/sdk/gotip/src/runtime/signal_unix.go:718 +0x2e5

goroutine 29 [syscall, locked to thread]:
runtime.cgocall(0x70a6a0, 0xc0000af508, 0xc0000af500)
        /home/gthomas/sdk/gotip/src/runtime/cgocall.go:154 +0x5b fp=0xc0000af4d8 sp=0xc0000af4a0 pc=0x41131b
github.com/godror/godror._Cfunc_dpiContext_getClientVersion(0x18847e0, 0xc000130270, 0x0)
        _cgo_gotypes.go:2621 +0x45 fp=0xc0000af508 sp=0xc0000af4d8 pc=0x5e5e25
github.com/godror/godror.(*drv).init.func2(0xc0000ec370, 0xc000130270, 0xc0000ec3c0)
        /home/gthomas/src/github.com/godror/godror/drv.go:261 +0x65 fp=0xc0000af540 sp=0xc0000af508 pc=0x62d5e5
github.com/godror/godror.(*drv).init(0xc0000ec370, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/gthomas/src/github.com/godror/godror/drv.go:261 +0x1b1 fp=0xc0000af660 sp=0xc0000af540 pc=0x5f8d91
github.com/godror/godror.(*drv).getPool(0xc0000ec370, 0x79db0b, 0x5, 0x0, 0x0, 0x79db11, 0x5, 0x0, 0x0, 0x0, ...)
        /home/gthomas/src/github.com/godror/godror/drv.go:560 +0xa5 fp=0xc0000af858 sp=0xc0000af660 pc=0x5fb6e5
github.com/godror/godror.(*drv).createConnFromParams(0xc0000ec370, 0x79db0b, 0x5, 0x0, 0x0, 0x79db11, 0x5, 0x0, 0x0, 0x0, ...)
        /home/gthomas/src/github.com/godror/godror/drv.go:534 +0x3e5 fp=0xc0000afc90 sp=0xc0000af858 pc=0x5fb5c5
github.com/godror/godror.(*drv).Open(0xc0000ec370, 0x79db0b, 0xb, 0x60130646, 0xc000160770, 0x49e6e6, 0x60130646)
        /home/gthomas/src/github.com/godror/godror/drv.go:275 +0x125 fp=0xc0000aff28 sp=0xc0000afc90 pc=0x5f93a5
github.com/godror/godror.TestNewDriver(0xc000083c80)
        /home/gthomas/src/github.com/godror/godror/drv_test.go:17 +0x76 fp=0xc0000aff80 sp=0xc0000aff28 pc=0x5e38d6
testing.tRunner(0xc000083c80, 0x7b55c0)
        /home/gthomas/sdk/gotip/src/testing/testing.go:1194 +0xef fp=0xc0000affd0 sp=0xc0000aff80 pc=0x51f4af
runtime.goexit()
        /home/gthomas/sdk/gotip/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc0000affd8 sp=0xc0000affd0 pc=0x47e5a1
created by testing.(*T).Run
        /home/gthomas/sdk/gotip/src/testing/testing.go:1239 +0x2b3
tgulacsi commented 3 years ago

With gdb, I've tried to look into what's going on: gotip test -c && mv godror.test.tip && gdb godror.test.tip, after run, I got the

Thread 1 "godror.test.tip" received signal SIGSEGV, Segmentation fault.
0x00000000006e662a in dpiContext_getClientVersion (context=0xb59ba0, versionInfo=0xc0001b0270)
    at /home/gthomas/src/github.com/godror/godror/odpi/embed/../src/dpiContext.c:260
260         memcpy(versionInfo, context->versionInfo, sizeof(dpiVersionInfo));
(gdb) p *context
$1 = {typeDef = 0x988ce0 <dpiAllTypeDefs+416>, checkInt = 3625685377, refCount = 1, env = 0x0,
  defaultEncoding = 0xb59c10 "UTF-8", defaultDriverName = 0xa630b0 "godror : v0.23.2", versionInfo = 0xba0,
  dpiMinorVersion = 1 '\001'}

Here the address of context->versionInfo=0xba0 is quite strange (short). Esp. when I compare it to the working 1.15.7:

go test -c && mv godror.test godror.test.15.7 && gdb godror.test.15.7:

(gdb) b dpiContext.c:260
Breakpoint 1 at 0x71177e: file /home/gthomas/src/github.com/godror/godror/odpi/embed/../src/dpiContext.c, line 260.
(gdb) run
Thread 1 "godror.test.15." hit Breakpoint 1, dpiContext_getClientVersion (context=0xab7030, versionInfo=0xc0001564c0)
    at /home/gthomas/src/github.com/godror/godror/odpi/embed/../src/dpiContext.c:260
260         memcpy(versionInfo, context->versionInfo, sizeof(dpiVersionInfo));
(gdb) p *context
$1 = {typeDef = 0x9ddce0 <dpiAllTypeDefs+416>, checkInt = 3625685377, refCount = 1, env = 0x0,
  defaultEncoding = 0xab7070 "UTF-8", defaultDriverName = 0xab7090 "godror : v0.23.2",
  versionInfo = 0xa2db60 <dpiOciLibVersionInfo>, dpiMinorVersion = 1 '\001'}

Here context->versionInfo=0xa2db60 is "longer".

bcmills commented 3 years ago

Here the address of context->versionInfo=0xba0 is quite strange (short).

That probably implies that context is NULL.

Is there a reason to believe that this is a bug in the Go toolchain or library? (Have you tried reproducing the failure using the same pattern of calls and inputs in a pure C program, and if so does it still reproduce?)

Have you tried running with GODEBUG=cgocheck=2, and/or under various C sanitizers (-fsanitize=address, -fsanitize=thread, -fsanitize=undefined, etc.)?

tgulacsi commented 3 years ago

context=0xb59ba0 - AFAIK that's not null.

As it has been working since Go 1.9, and works with 1.15.7, but fails with 1.16.rc1 (and tip), I think that highly correlates.

Works with GODEBUG=cgocheck=2, panics with cgocheck=0 and cgocheck=1.

How to use those sanitizers?

tgulacsi commented 3 years ago

gotip test -a -work -x -count=1 2>&1 | tee gotip.log: tip.zip

go test -count=1 -work -x -a 2>&1 | tee 15.log: 15.zip

bcmills commented 3 years ago

CC @ianlancetaylor @hajimehoshi

seankhliao commented 3 years ago

I get SIGSEV on master of godror for all of go1.14.13, go1.14.14, go1.15.6, go1.15.7, gotip (+c8bd801)

tgulacsi commented 3 years ago

@seankhliao do you have an Oracle client installed?

seankhliao commented 3 years ago

yes, on Arch using an unofficial repository

and earlier versions such as v0.23.0 test fine (or at least don't crash)

tgulacsi commented 3 years ago

@seankhliao thanks! Only TestNewDriver fails with GODEBUG=cgocheck={0,1} !

Maybe it's something fishy on the -dark- (C/OCI/ODPI) side that's triggered now without those write barriers...