Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: recover from check panic (#7763)

Danny Xud330855472dc
diff --git a/backend/runner/plancheck/executor.go b/backend/runner/plancheck/executor.go
index 8c195628bb..1cef30e9e5 100644
--- a/backend/runner/plancheck/executor.go
+++ b/backend/runner/plancheck/executor.go
@@ -3,11 +3,30 @@ package plancheck
import (
"context"
+ "github.com/pkg/errors"
+ "go.uber.org/zap"
+
+ "github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/plugin/db"
"github.com/bytebase/bytebase/backend/store"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
+func runExecutorOnce(ctx context.Context, exec Executor, planCheckRun *store.PlanCheckRunMessage) (results []*storepb.PlanCheckRunResult_Result, err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ panicErr, ok := r.(error)
+ if !ok {
+ panicErr = errors.Errorf("%v", r)
+ }
+ log.Error("TaskExecutor PANIC RECOVER", zap.Error(panicErr), zap.Stack("panic-stack"))
+ err = errors.Errorf("encounter internal error when executing check")
+ }
+ }()
+
+ return exec.Run(ctx, planCheckRun)
+}
+
// Executor is the plan check executor.
type Executor interface {
// Run will be called periodically by the plan check scheduler
diff --git a/backend/runner/plancheck/scheduler.go b/backend/runner/plancheck/scheduler.go
index 777aa52510..4d1009f94d 100644
--- a/backend/runner/plancheck/scheduler.go
+++ b/backend/runner/plancheck/scheduler.go
@@ -121,7 +121,7 @@ func (s *Scheduler) runPlanCheckRun(ctx context.Context, planCheckRun *store.Pla
s.stateCfg.InstanceOutstandingConnections[instanceUID]--
s.stateCfg.Unlock()
}()
- results, err := executor.Run(ctx, planCheckRun)
+ results, err := runExecutorOnce(ctx, executor, planCheckRun)
if err != nil {
s.markPlanCheckRunFailed(ctx, planCheckRun, err.Error())
return
diff --git a/backend/runner/taskcheck/executor.go b/backend/runner/taskcheck/executor.go
index bc8d66640a..33af7f106c 100644
--- a/backend/runner/taskcheck/executor.go
+++ b/backend/runner/taskcheck/executor.go
@@ -3,10 +3,30 @@ package taskcheck
import (
"context"
+ "github.com/pkg/errors"
+ "go.uber.org/zap"
+
+ "github.com/bytebase/bytebase/backend/common/log"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
)
+func runExecutorOnce(ctx context.Context, exec Executor, taskCheckRun *store.TaskCheckRunMessage, task *store.TaskMessage) (result []api.TaskCheckResult, err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ panicErr, ok := r.(error)
+ if !ok {
+ panicErr = errors.Errorf("%v", r)
+ }
+ log.Error("TaskChecker PANIC RECOVER", zap.Error(panicErr), zap.Stack("panic-stack"))
+ result = nil
+ err = errors.Errorf("encounter internal error when executing check")
+ }
+ }()
+
+ return exec.Run(ctx, taskCheckRun, task)
+}
+
// Executor is the task check executor.
type Executor interface {
// Run will be called periodically by the task check scheduler
diff --git a/backend/runner/taskcheck/scheduler.go b/backend/runner/taskcheck/scheduler.go
index 1e3feb4748..43bf82e762 100644
--- a/backend/runner/taskcheck/scheduler.go
+++ b/backend/runner/taskcheck/scheduler.go
@@ -129,7 +129,7 @@ func (s *Scheduler) Run(ctx context.Context, wg *sync.WaitGroup) {
s.stateCfg.InstanceOutstandingConnections[task.InstanceID]--
s.stateCfg.Unlock()
}()
- checkResultList, err := executor.Run(ctx, taskCheckRun, task)
+ checkResultList, err := runExecutorOnce(ctx, executor, taskCheckRun, task)
if err == nil {
bytes, err := json.Marshal(api.TaskCheckRunResultPayload{