diff --git a/src/jobservice/job/statemachine.go b/src/jobservice/job/statemachine.go index 196b732f7..9bf946451 100644 --- a/src/jobservice/job/statemachine.go +++ b/src/jobservice/job/statemachine.go @@ -77,6 +77,13 @@ func (sm *SM) EnterState(s string) (string, error) { // It will search the transit map if the next state is "_continue", and // will enter error state if there's more than one possible path when next state is "_continue" func (sm *SM) Start(s string) { + defer func() { + if r := recover(); r != nil { + sm.Logger.Errorf("Panic: %v, entering error state", r) + log.Warningf("Panic when handling job: %v, panic: %v, entering error state", sm.CurrentJob, r) + sm.EnterState(models.JobError) + } + }() n, err := sm.EnterState(s) log.Debugf("Job: %v, next state from handler: %s", sm.CurrentJob, n) for len(n) > 0 && err == nil {