Skip to content

Commit

Permalink
Merge pull request goharbor#2553 from reasonerjt/master
Browse files Browse the repository at this point in the history
State machine recover from panic and set job state to error
  • Loading branch information
reasonerjt committed Jun 16, 2017
2 parents 482f91d + 7a57cb4 commit 4993646
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/jobservice/job/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4993646

Please sign in to comment.