idcos / osinstall-server

OSInstall server
GNU General Public License v3.0
63 stars 54 forks source link

启动服务时,若mysql连接失败,潜在的空指针就会导致进程意外退出。 #7

Closed voidint closed 7 years ago

voidint commented 7 years ago
2016/13/26 14:59:15 [repo.go:67][E] database connection failed:dial tcp [::1]:3306: getsockopt: connection refused
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x40028d4]

goroutine 1 [running]:
panic(0x4551060, 0xc42000c1f0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
main.runServer(0xc420155400)
    /Users/voidint/cloud/workspace/go/lib/src/github.com/idcos/osinstall-server/src/cmd/cloudboot-server/main.go:51 +0x104
main.main.func1(0xc420155400)
    /Users/voidint/cloud/workspace/go/lib/src/github.com/idcos/osinstall-server/src/cmd/cloudboot-server/main.go:37 +0x74
github.com/codegangsta/cli.(*App).Run(0xc420084f20, 0xc42000c3a0, 0x1, 0x1, 0x0, 0x0)
    /Users/voidint/cloud/workspace/go/lib/src/github.com/idcos/osinstall-server/vendor/src/github.com/codegangsta/cli/app.go:201 +0xba7
main.main()
    /Users/voidint/cloud/workspace/go/lib/src/github.com/idcos/osinstall-server/src/cmd/cloudboot-server/main.go:40 +0x1df
voidint commented 7 years ago
srvr, err := osinstallserver.NewServer(configFile, osinstallserver.DevPipeline)
if err != nil {
    srvr.Log.Error(err)
    return
}

导致进程退出的这个空指针出现在srvr.Log.Error(err)。当srvr==nil,再去使用srvr.Log,导致panic是必然的。