Skip to content

Commit e4f1a5d

Browse files
authored
Fix panic on cancel stage while executing (#6275)
Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
1 parent f77d57c commit e4f1a5d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pkg/app/pipedv1/controller/scheduler.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,23 @@ func (s *scheduler) executeStage(sig StopSignal, ps *model.PipelineStage) (final
603603
TargetDeploymentSource: tds.ToPluginDeploySource(),
604604
},
605605
})
606-
// do not return error if the context is already canceled.
607-
// this occurs when the stage is canceled.
608-
// otherwise, return the error.
609-
if err != nil && ctx.Err() == nil {
606+
607+
// Handle context error.
608+
if ctx.Err() != nil {
609+
if ctx.Err() == context.Canceled {
610+
s.logger.Info("stage execution cancelled", zap.String("stage-name", ps.Name))
611+
return model.StageStatus_STAGE_CANCELLED
612+
}
613+
if ctx.Err() == context.DeadlineExceeded {
614+
s.logger.Info("stage execution timed out", zap.String("stage-name", ps.Name))
615+
return model.StageStatus_STAGE_FAILURE
616+
}
617+
s.logger.Error("stage execution context failed", zap.String("stage-name", ps.Name), zap.Error(ctx.Err()))
618+
return model.StageStatus_STAGE_FAILURE
619+
}
620+
621+
// Handle plugin execution failure.
622+
if err != nil {
610623
s.logger.Error("failed to execute stage", zap.String("stage-name", ps.Name), zap.Error(err))
611624
return model.StageStatus_STAGE_FAILURE
612625
}

0 commit comments

Comments
 (0)