Golang 中国

我在写一个基于 OVS 的隧道。

main 函数中调用 NewOVSBridge() 函数,由于某些必要性参数未给出,所以我在 NewOVSBridge() 函数中进行了 panic(注:不要问为什么不返回 error,因为我有自己的原因,所以 panic 了),如:panic(fmt.Errorf("one of mac, arp and ip learning must be given")),此时,当运行程序时,抛出了恐慌:

panic: fatal error: malloc deadlock
panic during panic

runtime stack:
runtime.startpanic_m()
        C:/Go/src/runtime/panic.go:693 +0x179
runtime.systemstack(0x0)
        C:/Go/src/runtime/asm_amd64.s:409 +0x79
runtime.mstart()
        C:/Go/src/runtime/proc.go:1170

goroutine 1 [running]:
runtime.systemstack_switch()
        C:/Go/src/runtime/asm_amd64.s:363 fp=0xc420053890 sp=0xc420053888 pc=0x453a40
runtime.startpanic()
        C:/Go/src/runtime/panic.go:592 +0x1e fp=0xc4200538a8 sp=0xc420053890 pc=0x42994e
runtime.throw(0x80a302, 0xf)
        C:/Go/src/runtime/panic.go:618 +0x74 fp=0xc4200538c8 sp=0xc4200538a8 pc=0x429a74
runtime.mallocgc(0x2010, 0x0, 0x79e801, 0x7395be)
        C:/Go/src/runtime/malloc.go:621 +0x99d fp=0xc420053968 sp=0xc4200538c8 pc=0x41084d
runtime.itabAdd(0x7f9ac93c8308)
        C:/Go/src/runtime/iface.go:122 +0x83 fp=0xc4200539b8 sp=0xc420053968 pc=0x40d6c3
runtime.getitab(0x79e800, 0x773c20, 0xc4201f9601, 0xc4201f9670)
        C:/Go/src/runtime/iface.go:70 +0x404 fp=0xc420053a30 sp=0xc4200539b8 pc=0x40d544
runtime.assertE2I2(0x79e800, 0x773c20, 0xc420203b60, 0x7, 0xc400000007, 0xc420053ac0)
        C:/Go/src/runtime/iface.go:592 +0x43 fp=0xc420053a60 sp=0xc420053a30 pc=0x40eaa3
runtime.printany(0x773c20, 0xc420203b60)
        C:/Go/src/runtime/error.go:77 +0x69 fp=0xc420053b20 sp=0xc420053a60 pc=0x405a49
runtime.printpanics(0xc420053ba8)
        C:/Go/src/runtime/panic.go:420 +0x71 fp=0xc420053b40 sp=0xc420053b20 pc=0x429191
panic(0x78e460, 0xc420203b50)
        C:/Go/src/runtime/panic.go:553 +0x3b4 fp=0xc420053be0 sp=0xc420053b40 pc=0x4295d4
main.NewOVSBridge(0xc4200de3b0, 0xb, 0x8044e5, 0x6, 0xe10, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        D:/gopath/src/tunnel/ovs_bridge.go:114 +0x2b8 fp=0xc420053c58 sp=0xc420053be0 pc=0x729028
main.main()
        D:/gopath/src/tunnel/main.go:102 +0x4a7 fp=0xc420053f88 sp=0xc420053c58 pc=0x726e57
runtime.main()
        C:/Go/src/runtime/proc.go:198 +0x212 fp=0xc420053fe0 sp=0xc420053f88 pc=0x42b2f2
runtime.goexit()
        C:/Go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420053fe8 sp=0xc420053fe0 pc=0x456521

查看原因,说是在 panic 时又发生了第二次 panic

如果我把 panic 代码改成 panic("test panic"),结果就不会发生 panic in panic 了。

有没有大神知道为什么?难道是 go runtime 的 BUG?,但写小程序测试 panic(fmt.Errorf("test panic")),又没有发生 panic in panic

0 回复
需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。