Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt/execbuilder: add panic catching to buildRoutinePlanGenerator #99835

Merged
merged 1 commit into from
Mar 31, 2023
Merged
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
26 changes: 25 additions & 1 deletion pkg/sql/opt/exec/execbuilder/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree/treecmp"
"github.com/cockroachdb/cockroach/pkg/sql/sem/volatility"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/errorutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
)
Expand Down Expand Up @@ -946,7 +948,29 @@ func (b *Builder) buildRoutinePlanGenerator(
var o xform.Optimizer
planGen := func(
ctx context.Context, ref tree.RoutineExecFactory, args tree.Datums, fn tree.RoutinePlanGeneratedFunc,
) error {
) (err error) {
defer func() {
if r := recover(); r != nil {
// This code allows us to propagate internal errors without
// having to add error checks everywhere throughout the code.
// This is only possible because the code does not update shared
// state and does not manipulate locks.
//
// This is the same panic-catching logic that exists in
// o.Optimize() below. It's required here because it's possible
// for factory functions to panic below, like
// CopyAndReplaceDefault.
if ok, e := errorutil.ShouldCatch(r); ok {
err = e
log.VEventf(ctx, 1, "%v", err)
} else {
// Other panic objects can't be considered "safe" and thus
// are propagated as crashes that terminate the session.
panic(r)
}
}
}()

for i := range stmts {
stmt := stmts[i]
o.Init(ctx, b.evalCtx, b.catalog)
Expand Down