Skip to content

Commit

Permalink
catch panic
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlh committed Dec 14, 2019
1 parent a4e7461 commit 3b24752
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/nps/nps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/astaxie/beego"
Expand Down Expand Up @@ -64,6 +65,7 @@ func main() {
"After=network-online.target syslog.target"}
}
prg := &nps{}
prg.exit = make(chan struct{})
s, err := service.New(prg, svcConfig)
if err != nil {
logs.Error(err)
Expand Down Expand Up @@ -123,6 +125,14 @@ func (p *nps) Stop(s service.Service) error {
}

func (p *nps) run() error {
defer func() {
if err := recover(); err != nil {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
logs.Warning("nps: panic serving %v: %v\n%s", err, string(buf))
}
}()
routers.Init()
task := &file.Tunnel{
Mode: "webServer",
Expand Down

0 comments on commit 3b24752

Please sign in to comment.