Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions pkg/app/piped/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,40 @@ func (s *scheduler) Run(ctx context.Context) error {
<-doneCh

case cmd := <-s.cancelledCh:
// A nil command means the channel was closed after delivering
// a cancel command, so treat it as a cancellation as well.
if cmd != nil {
cancelCommand = cmd
cancelCommander = cmd.Commander
handler.Cancel()
<-doneCh
}
handler.Cancel()
<-doneCh

case <-doneCh:
break
}

// The select may have picked doneCh while a cancel command was already
// waiting, so check it before deciding to move on.
if cancelCommand == nil {
select {
case cmd := <-s.cancelledCh:
if cmd != nil {
cancelCommand = cmd
cancelCommander = cmd.Commander
}
default:
}
}

// A received cancel command wins even if the stage finished successfully,
// otherwise the loop would continue to the next stage after the user cancelled.
if cancelCommand != nil {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_CANCELLED
statusReason = fmt.Sprintf("Cancelled by %s while executing stage %s", cancelCommander, ps.Id)
break
}

// If all operations of the stage were completed successfully or skipped by a web user
// handle the next stage.
if result == model.StageStatus_STAGE_SUCCESS || result == model.StageStatus_STAGE_SKIPPED {
Expand Down
27 changes: 25 additions & 2 deletions pkg/app/pipedv1/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,14 @@ func (s *scheduler) Run(ctx context.Context) error {
<-doneCh

case cmd := <-s.cancelledCh:
// A nil command means the channel was closed after delivering
// a cancel command, so treat it as a cancellation as well.
if cmd != nil {
cancelCommand = cmd
cancelCommander = cmd.Commander
handler.Cancel()
<-doneCh
}
handler.Cancel()
<-doneCh
Comment on lines 372 to +380

case <-timeout:
handler.Timeout()
Expand All @@ -385,6 +387,27 @@ func (s *scheduler) Run(ctx context.Context) error {
break
}

// The select may have picked doneCh while a cancel command was already
// waiting, so check it before deciding to move on.
if cancelCommand == nil {
select {
case cmd := <-s.cancelledCh:
if cmd != nil {
cancelCommand = cmd
cancelCommander = cmd.Commander
}
default:
}
}

// A received cancel command wins even if the stage finished successfully,
// otherwise the loop would continue to the next stage after the user cancelled.
if cancelCommand != nil {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_CANCELLED
statusReason = fmt.Sprintf("Cancelled by %s while executing stage %s", cancelCommander, ps.Id)
break
}

// If all operations of the stage were completed successfully or skipped by a web user
// handle the next stage.
if result == model.StageStatus_STAGE_SUCCESS || result == model.StageStatus_STAGE_SKIPPED {
Expand Down
Loading