Skip to content

Commit

Permalink
planner: handle panic when loading bindings at startup (pingcap#58017) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 9, 2024
1 parent 5a138ef commit 9db025d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/bindinfo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ go_library(
"//pkg/util/table-filter",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pkg_errors//:errors",
"@org_golang_x_sync//singleflight",
"@org_uber_go_zap//:zap",
],
Expand Down
9 changes: 8 additions & 1 deletion pkg/bindinfo/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/hint"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -130,7 +131,13 @@ func HasAvailableBinding(br Bindings) bool {

// prepareHints builds ID and Hint for Bindings. If sctx is not nil, we check if
// the BindSQL is still valid.
func prepareHints(sctx sessionctx.Context, binding *Binding) error {
func prepareHints(sctx sessionctx.Context, binding *Binding) (rerr error) {
defer func() {
if r := recover(); r != nil {
rerr = errors.Errorf("panic when preparing hints for binding %v, panic: %v", binding.BindSQL, r)
}
}()

p := parser.New()
if (binding.Hint != nil && binding.ID != "") || binding.Status == deleted {
return nil
Expand Down

0 comments on commit 9db025d

Please sign in to comment.