From e613146343b979e0e33e05baa76129a68feb34bc Mon Sep 17 00:00:00 2001 From: stonezdj Date: Thu, 8 Dec 2022 13:48:05 +0800 Subject: [PATCH] Avoid internal error in the UI when reset a schedule fixes #17926 Signed-off-by: stonezdj --- src/pkg/scheduler/scheduler.go | 8 +++++++- src/pkg/task/execution.go | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pkg/scheduler/scheduler.go b/src/pkg/scheduler/scheduler.go index bab6b43c090..1ac5dda3e87 100644 --- a/src/pkg/scheduler/scheduler.go +++ b/src/pkg/scheduler/scheduler.go @@ -196,7 +196,13 @@ func (s *scheduler) UnScheduleByID(ctx context.Context, id int64) error { executionID := executions[0].ID // stop the execution if err = s.execMgr.StopAndWait(ctx, executionID, 10*time.Second); err != nil { - return err + if err == task.ErrTimeOut { + // Avoid return this error to the UI, log time out error and continue + // the execution will be finally stopped by jobservice + log.Debugf("time out when stopping the execution %d, but the execution will be stopped eventually", executionID) + } else { + return err + } } // delete execution if err = s.execMgr.Delete(ctx, executionID); err != nil { diff --git a/src/pkg/task/execution.go b/src/pkg/task/execution.go index 1f4d2f8a03c..3d8582698ed 100644 --- a/src/pkg/task/execution.go +++ b/src/pkg/task/execution.go @@ -17,7 +17,6 @@ package task import ( "context" "encoding/json" - "fmt" "sync" "time" @@ -34,6 +33,7 @@ var ( // ExecMgr is a global execution manager instance ExecMgr = NewExecutionManager() executionSweeperCount = map[string]uint8{} + ErrTimeOut = errors.New("stopping the execution timeout") ) // ExecutionManager manages executions. @@ -333,7 +333,7 @@ func (e *executionManager) StopAndWait(ctx context.Context, id int64, timeout ti lock.Lock() overtime = true lock.Unlock() - return fmt.Errorf("stopping the execution %d timeout", id) + return ErrTimeOut case err := <-errChan: return err }