1
0
Fork 0

Handle panic debug on the Satan side

This commit is contained in:
Gregory Eremin 2015-10-24 02:40:20 +03:00
parent 182cfa3e40
commit d2041b69a1
2 changed files with 8 additions and 10 deletions

View File

@ -172,16 +172,8 @@ func (d *BaseDaemon) base() *BaseDaemon {
return d return d
} }
func (d *BaseDaemon) handlePanic() { func (d *BaseDaemon) handlePanic(err interface{}) {
err := recover()
if err == nil {
return
}
d.stats.registerError()
if d.panicHandler != nil { if d.panicHandler != nil {
d.panicHandler(err) d.panicHandler(err)
} }
log.Printf("Daemon %s recovered from a panic\nError: %v\n", d, err)
debug.PrintStack()
} }

View File

@ -169,11 +169,17 @@ func (s *Satan) processSystemTask(t *task) {
} }
func (s *Satan) processGeneralTask(t *task) { func (s *Satan) processGeneralTask(t *task) {
defer t.daemon.base().handlePanic()
defer func(start time.Time) { defer func(start time.Time) {
dur := time.Now().UnixNano() - start.UnixNano() dur := time.Now().UnixNano() - start.UnixNano()
t.daemon.base().stats.add(time.Duration(dur)) t.daemon.base().stats.add(time.Duration(dur))
}(time.Now()) }(time.Now())
defer func() {
if err := recover(); err != nil {
t.daemon.base().handlePanic(err)
log.Printf("Daemon %s recovered from a panic\nError: %v\n", t.daemon.base(), err)
debug.PrintStack()
}
}()
t.actor() // <--- THE ACTION HAPPENS HERE t.actor() // <--- THE ACTION HAPPENS HERE
} }