Skip to content

Instantly share code, notes, and snippets.

@zeebo

zeebo/main.go Secret

Last active Aug 29, 2015
Embed
What would you like to do?
Bug Repro Source

Sample failure stacktrace

$ GOTRACEBACK=2 ./test.test 
runtime: unexpected return pc for runtime.starttheworld called from 0xffffffff
fatal error: unknown caller pc

runtime stack:
runtime.throw(0x40c3f9)
	/home/jeff/jeff/go-tip/src/pkg/runtime/panic.c:520 +0x5c fp=0x42bc7ad4
runtime.gentraceback(0x14a1c, 0x405ecf1c, 0x0, 0x106023c0, 0x0, 0x0, 0x7fffffff, 0x18ff0, 0x42bc7bd0, 0x0)
	/home/jeff/jeff/go-tip/src/pkg/runtime/traceback_arm.c:107 +0x300 fp=0x42bc7b48
addstackroots(0x106023c0, 0x42bc7bd0)
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:1678 +0x184 fp=0x42bc7b90
markroot(0x10624000, 0x8)
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:1311 +0xf8 fp=0x42bc7bd4
runtime.parfordo(0x10624000)
	/home/jeff/jeff/go-tip/src/pkg/runtime/parfor.c:88 +0xc0 fp=0x42bc7c48
gc(0x405dfcd4)
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:2389 +0x1f8 fp=0x42bc7d90
mgc(0x106020a0)
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:2331 +0x30 fp=0x42bc7d98
runtime.mcall(0x10614000)
	/home/jeff/jeff/go-tip/src/pkg/runtime/asm_arm.s:163 +0x3c fp=0x42bc7da0

goroutine 16 [garbage collection]:
runtime.gc(0x0)
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:2311 +0x1bc fp=0x405dfcdc
runtime.mallocgc(0x10, 0x241528, 0x1)
	/home/jeff/jeff/go-tip/src/pkg/runtime/malloc.goc:204 +0x1b0 fp=0x405dfd14
cnew(0x241528, 0x1, 0x0)
	/home/jeff/jeff/go-tip/src/pkg/runtime/malloc.goc:835 +0xc8 fp=0x405dfd24
runtime.cnew(0x241528)
	/home/jeff/jeff/go-tip/src/pkg/runtime/malloc.goc:842 +0x3c fp=0x405dfd34
copyin(0x241528, 0x405dfdb4, 0x405dfd70)
	/home/jeff/jeff/go-tip/src/pkg/runtime/iface.goc:164 +0x6c fp=0x405dfd50
runtime.convT2E(0x241528, 0x405dfdb4, 0x241528, 0x0)
	/home/jeff/jeff/go-tip/src/pkg/runtime/iface.goc:207 +0x34 fp=0x405dfd60
testing.(*T).report(0x10604180)
	/home/jeff/jeff/go-tip/src/pkg/testing/testing.go:449 +0x184 fp=0x405dfe34
testing.RunTests(0x338814, 0x408cf0, 0x1, 0x1, 0x42a001)
	/home/jeff/jeff/go-tip/src/pkg/testing/testing.go:513 +0x774 fp=0x405dff18
testing.Main(0x338814, 0x408cf0, 0x1, 0x1, 0x4270d0, 0x0, 0x0, 0x4270d0, 0x0, 0x0)
	/home/jeff/jeff/go-tip/src/pkg/testing/testing.go:435 +0x6c fp=0x405dff64
main.main()
	test/_test/_testmain.go:47 +0x98 fp=0x405dff90
runtime.main()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:247 +0xf8 fp=0x405dffc4
runtime.goexit()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:1445 fp=0x405dffc4
created by _rt0_go
	/home/jeff/jeff/go-tip/src/pkg/runtime/asm_arm.s:72 +0xb0

goroutine 17 [syscall]:
runtime.notetsleepg(0x405eefa0, 0xf8475800, 0xd)
	/home/jeff/jeff/go-tip/src/pkg/runtime/lock_futex.c:197 +0x40 fp=0x405eef7c
runtime.MHeap_Scavenger()
	/home/jeff/jeff/go-tip/src/pkg/runtime/mheap.c:531 +0xe4 fp=0x405eefcc
runtime.goexit()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:1445 fp=0x405eefcc
created by runtime.main
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:207

goroutine 18 [runnable]:
runtime.gosched()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:1419 +0x44 fp=0x405edfc0
bgsweep()
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:1968 +0x54 fp=0x405edfcc
runtime.goexit()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:1445 fp=0x405edfcc
created by runtime.gc
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:2251

goroutine 19 [runnable]:
runtime.cgocallbackg()
	/home/jeff/jeff/go-tip/src/pkg/runtime/cgocall.c:244 +0x38 fp=0x405ecf24
runtime.cgocallback_gofunc(0x112804, 0xed74, 0x405ecf70)
	/home/jeff/jeff/go-tip/src/pkg/runtime/asm_arm.s:501 +0x60 fp=0x405ecf30
runtime.asmcgocall(0xed74, 0x405ecf70)
	/home/jeff/jeff/go-tip/src/pkg/runtime/asm_arm.s:417 +0x24 fp=0x405ecf34
exitsyscall0(0xed74)
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:1668 fp=0x405ecf34
github.com/SpaceMonkeyGo/openssl._Cfunc_SSL_free(0x0)
	github.com/SpaceMonkeyGo/openssl/_obj/_cgo_defun.c:991 +0x34 fp=0x405ecf40
github.com/SpaceMonkeyGo/openssl._Cfunc_SSL_free(0x1addc)
	github.com/SpaceMonkeyGo/openssl/_obj/_cgo_defun.c:991 +0x34 fp=0x405ecf4c
runtime: unexpected return pc for runtime.starttheworld called from 0xffffffff
runtime.starttheworld()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:568 +0x100 fp=0x405ecf6c
created by runtime.gc
	/home/jeff/jeff/go-tip/src/pkg/runtime/mgc0.c:2251

goroutine 17 [syscall]:
runtime.goexit()
	/home/jeff/jeff/go-tip/src/pkg/runtime/proc.c:1445 fp=0x405e9fd0

Steps to reproduce

  1. Be on an ARM machine with Go on tip and OpenSSL from debian wheezy (it probably works with other OpenSSL versions, I just haven't tested) :(
  2. go get -d gist.github.com/364a43f3d2ddfb80f9f8.git.git
  3. go test gist.github.com/364a43f3d2ddfb80f9f8.git.git

Things to note

  • The error only happens on ARM with GC enabled.
  • GOGC is set to 0 in init() to trigger it reliably.
  • It doesn't happen on Go 1.2.1.
  • It does happen on Go 1.3 beta and current tip (b6591f566db4).
  • Having GOMAXPROCS high reduces the probability of it failing.
  • Running it in main (just go build) does not cause the failure, only in the test runner.
package main
import (
"log"
"net"
"runtime"
"runtime/debug"
"sync"
"github.com/SpaceMonkeyGo/openssl"
)
var (
certBytes = []byte(`-----BEGIN CERTIFICATE-----
MIIDxDCCAqygAwIBAgIVAMcK/0VWQr2O3MNfJCydqR7oVELcMA0GCSqGSIb3DQEB
BQUAMIGQMUkwRwYDVQQDE0A1NjdjZGRmYzRjOWZiNTYwZTk1M2ZlZjA1N2M0NGFm
MDdiYjc4MDIzODIxYTA5NThiY2RmMGMwNzJhOTdiMThhMQswCQYDVQQGEwJVUzEN
MAsGA1UECBMEVXRhaDEQMA4GA1UEBxMHTWlkdmFsZTEVMBMGA1UEChMMU3BhY2Ug
TW9ua2V5MB4XDTEzMTIxNzE4MzgyMloXDTIzMTIxNTE4MzgyMlowgZAxSTBHBgNV
BAMTQDM4NTg3ODRkMjU1NTdiNTM1MWZmNjRmMmQzMTQ1ZjkwYTJlMTIzMDM4Y2Yz
Mjc1Yzg1OTM1MjcxYWIzMmNiMDkxCzAJBgNVBAYTAlVTMQ0wCwYDVQQIEwRVdGFo
MRAwDgYDVQQHEwdNaWR2YWxlMRUwEwYDVQQKEwxTcGFjZSBNb25rZXkwggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDdf3icNvFsrlrnNLi8SocscqlSbFq+
pEvmhcSoqgDLqebnqu8Ld73HJJ74MGXEgRX8xZT5FinOML31CR6t9E/j3dqV6p+G
fdlFLe3IqtC0/bPVnCDBirBygBI4uCrMq+1VhAxPWclrDo7l9QRYbsExH9lfn+Ry
vxeNMZiOASasvVZNncY8E9usBGRdH17EfDL/TPwXqWOLyxSN5o54GTztjjy9w9CG
QP7jcCueKYyQJQCtEmnwc6P/q6/EPv5R6drBkX6lo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GBth+xW6g+WA8y0z76ZSaWpFi8lVM4=
-----END RSA PRIVATE KEY-----
`)
)
func pipe() (net.Conn, net.Conn) {
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
log.Fatal(err)
}
defer l.Close()
client_ch := make(chan net.Conn, 1)
go func() {
client, err := net.Dial(l.Addr().Network(), l.Addr().String())
if err != nil {
log.Fatal(err)
}
client_ch <- client
}()
server_conn, err := l.Accept()
if err != nil {
log.Fatal(err)
}
return server_conn, <-client_ch
}
type HandshakingConn interface {
net.Conn
Handshake() error
}
func passThruVerify(ok bool, store *openssl.CertificateStoreCtx) bool {
cert := store.GetCurrentCert()
if cert == nil {
log.Fatal("Could not obtain cert from store\n")
}
sn := cert.GetSerialNumberHex()
if len(sn) == 0 {
log.Fatal("Could not obtain serial number from cert")
}
return ok
}
func opensslWrap(server_conn, client_conn net.Conn) (
server, client HandshakingConn) {
ctx, err := openssl.NewCtx()
if err != nil {
log.Fatal(err)
}
ctx.SetVerify(openssl.VerifyNone, passThruVerify)
key, err := openssl.LoadPrivateKeyFromPEM(keyBytes)
if err != nil {
log.Fatal(err)
}
err = ctx.UsePrivateKey(key)
if err != nil {
log.Fatal(err)
}
cert, err := openssl.LoadCertificateFromPEM(certBytes)
if err != nil {
log.Fatal(err)
}
err = ctx.UseCertificate(cert)
if err != nil {
log.Fatal(err)
}
err = ctx.SetCipherList("AES128-SHA")
if err != nil {
log.Fatal(err)
}
server, err = openssl.Server(server_conn, ctx)
if err != nil {
log.Fatal(err)
}
client, err = openssl.Client(client_conn, ctx)
if err != nil {
log.Fatal(err)
}
return server, client
}
func runTest() {
{
server_conn, client_conn := pipe()
server, client := opensslWrap(server_conn, client_conn)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
err := client.Handshake()
if err != nil {
log.Fatal(err)
}
}()
go func() {
defer wg.Done()
err := server.Handshake()
if err != nil {
log.Fatal(err)
}
}()
wg.Wait()
if err := server.Close(); err != nil {
log.Fatal(err)
}
if err := client.Close(); err != nil {
log.Fatal(err)
}
}
for i := 0; i < 100; i++ {
runtime.GC()
}
}
func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
debug.SetGCPercent(0)
}
func main() {
runTest()
}
package main
import "testing"
func TestSomethingFoo(t *testing.T) {
runTest()
}
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.