golang log.Printf 崩溃

huangapple go评论115阅读模式
英文:

golang log.Printf crash

问题

以下是要翻译的内容:

在我的Mac上运行2或3秒后,以下代码崩溃了,但在CentOS 7上没有问题,我使用的是Go 1.6.3。

问题:

  1. 是什么导致了这样的崩溃?

  2. 如何避免它?(不是从中恢复)

  3. 以下堆栈的参数是什么意思?

     log.Printf(0x1068d8, 0x6, 0x0, 0x0, 0x0)
    

    函数签名是:

     Print(v ...interface{})
    

崩溃的代码:

package main
import (
    "log"
)

func main() {
    for {
       log.Printf("hello")
    }
}

它将在10秒钟内崩溃,并打印:

2017/09/02 21:50:01 hello
2017/09/02 21:50:01 hello
2017/09/02 21:50:01 hello
2017/09/02 21:50:01 hello
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x1777d0d1d11 pc=0x92f60]

goroutine 1 [running]:
runtime.throw(0x12c000, 0x2a)
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/panic.go:547 +0x90 fp=0xc820035da0 sp=0xc820035d88
runtime.sigpanic()
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/sigpanic_unix.go:12 +0x5a fp=0xc820035df0 sp=0xc820035da0
sync.(*Pool).Get(0x1991e0, 0x0, 0x0)
    /usr/local/Cellar/go/1.6.3/libexec/src/sync/pool.go:102 +0x40 fp=0xc820035e40 sp=0xc820035df0
fmt.newPrinter(0xed13cae09)
    /usr/local/Cellar/go/1.6.3/libexec/src/fmt/print.go:133 +0x27 fp=0xc820035e80 sp=0xc820035e40
fmt.Sprintf(0x1068d8, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.6.3/libexec/src/fmt/print.go:202 +0x2b fp=0xc820035ed0 sp=0xc820035e80
log.Printf(0x1068d8, 0x6, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.6.3/libexec/src/log/log.go:289 +0x49 fp=0xc820035f20 sp=0xc820035ed0
main.main()
    /Users/haoy/video_projects/rtc-xswitch2/app/recorder/src/test.go:11 +0x3d fp=0xc820035f50 sp=0xc820035f20
runtime.main()
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/proc.go:188 +0x2b0 fp=0xc820035fa0 sp=0xc820035f50
runtime.goexit()
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc820035fa8 sp=0xc820035fa0
exit status 2
英文:

Following code crash on my mac after running 2 or 3 seconds, but it's okay on centos 7, and, I am on go 1.6.3.

Questions:

  1. What caused such crash?

  2. How to avoid it? (Not recover from it)

  3. What does arguments of following stack means?

    log.Printf(0x1068d8, 0x6, 0x0, 0x0, 0x0)
    

    the signature is:

    Print(v ...interface{})
    

The crashed code:

package main
import (
    "log"
)

func main() {
    for {
       log.Printf("hello")
    }
}

It will crash in 10 seconds, and prints:

2017/09/02 21:50:01 hello
2017/09/02 21:50:01 hello
2017/09/02 21:50:01 hello
2017/09/02 21:50:01 hello
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x1777d0d1d11 pc=0x92f60]

goroutine 1 [running]:
runtime.throw(0x12c000, 0x2a)
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/panic.go:547 +0x90 fp=0xc820035da0 sp=0xc820035d88
runtime.sigpanic()
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/sigpanic_unix.go:12 +0x5a fp=0xc820035df0 sp=0xc820035da0
sync.(*Pool).Get(0x1991e0, 0x0, 0x0)
    /usr/local/Cellar/go/1.6.3/libexec/src/sync/pool.go:102 +0x40 fp=0xc820035e40 sp=0xc820035df0
fmt.newPrinter(0xed13cae09)
    /usr/local/Cellar/go/1.6.3/libexec/src/fmt/print.go:133 +0x27 fp=0xc820035e80 sp=0xc820035e40
fmt.Sprintf(0x1068d8, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.6.3/libexec/src/fmt/print.go:202 +0x2b fp=0xc820035ed0 sp=0xc820035e80
log.Printf(0x1068d8, 0x6, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.6.3/libexec/src/log/log.go:289 +0x49 fp=0xc820035f20 sp=0xc820035ed0
main.main()
    /Users/haoy/video_projects/rtc-xswitch2/app/recorder/src/test.go:11 +0x3d fp=0xc820035f50 sp=0xc820035f20
runtime.main()
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/proc.go:188 +0x2b0 fp=0xc820035fa0 sp=0xc820035f50
runtime.goexit()
    /usr/local/Cellar/go/1.6.3/libexec/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc820035fa8 sp=0xc820035fa0
exit status 2

答案1

得分: 5

code 0x0b 是 11,代表 SIGSEGV。

我之前在 Mac 上使用 Go 1.6.3 时也遇到过这个错误,可以参考 "go get 报错 'fatal error: unexpected signal during runtime execution'"。
升级是最理想的解决方法3

更多信息请参见 go/go 问题 17824cl 32882

> doc/devel/release.html: 文档中指出 go1.6.3 实际上不支持 macOS Sierra。

英文:

code 0x0b is 11, which is SIGSEGV..

I have seen that error before onMac with Go 1.6.3: see "go get throws 'fatal error: unexpected signal during runtime execution'".
Upgrading would be ideal.

See go/go issue 17824 for more, and cl 32882:

> doc/devel/release.html: document go1.6.3 doesn't actually support macOS Sierra.

huangapple
  • 本文由 发表于 2017年9月2日 22:19:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/46014717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定