Skip to content

Commit 00f15fc

Browse files
authored
executor: replace Call with CallWithRecover in the close of hash join v1 (#61868) (#62343)
close #60926
1 parent 8658c99 commit 00f15fc

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

executor/hash_table.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"unsafe"
2424

2525
"github.com/pingcap/errors"
26+
"github.com/pingcap/failpoint"
2627
"github.com/pingcap/tidb/sessionctx"
2728
"github.com/pingcap/tidb/sessionctx/stmtctx"
2829
"github.com/pingcap/tidb/types"
@@ -501,6 +502,8 @@ func (c *hashRowContainer) Len() uint64 {
501502
}
502503

503504
func (c *hashRowContainer) Close() error {
505+
failpoint.Inject("issue60926", nil)
506+
504507
defer c.memTracker.Detach()
505508
c.chkBuf = nil
506509
return c.rowContainer.Close()

executor/join.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ import (
3939
"github.com/pingcap/tidb/util/dbterror/exeerrors"
4040
"github.com/pingcap/tidb/util/disk"
4141
"github.com/pingcap/tidb/util/execdetails"
42+
"github.com/pingcap/tidb/util/logutil"
4243
"github.com/pingcap/tidb/util/memory"
44+
"go.uber.org/zap"
4345
)
4446

47+
// IsChildCloseCalledForTest is used for test
48+
var IsChildCloseCalledForTest atomic.Bool
49+
4550
var (
4651
_ Executor = &HashJoinExec{}
4752
_ Executor = &NestedLoopApplyExec{}
@@ -172,7 +177,14 @@ func (e *HashJoinExec) Close() error {
172177
channel.Clear(e.probeWorkers[i].joinChkResourceCh)
173178
}
174179
e.probeSideTupleFetcher.probeChkResourceCh = nil
175-
terror.Call(e.rowContainer.Close)
180+
util.WithRecovery(func() {
181+
err := e.rowContainer.Close()
182+
if err != nil {
183+
logutil.BgLogger().Error("RowContainer encounters error",
184+
zap.Error(err),
185+
zap.Stack("stack trace"))
186+
}
187+
}, nil)
176188
e.hashJoinCtx.sessCtx.GetSessionVars().MemTracker.UnbindActionFromHardLimit(e.rowContainer.ActionSpill())
177189
e.waiterWg.Wait()
178190
}
@@ -193,8 +205,8 @@ func (e *HashJoinExec) Close() error {
193205
if e.stats != nil {
194206
defer e.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.RegisterStats(e.id, e.stats)
195207
}
196-
err := e.baseExecutor.Close()
197-
return err
208+
IsChildCloseCalledForTest.Store(true)
209+
return e.baseExecutor.Close()
198210
}
199211

200212
// Open implements the Executor Open interface.

executor/test/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ go_test(
99
"main_test.go",
1010
],
1111
flaky = True,
12+
shard_count = 3,
1213
deps = [
14+
"//executor",
1315
"//testkit",
16+
"@com_github_pingcap_failpoint//:failpoint",
17+
"@com_github_stretchr_testify//require",
1418
"@org_uber_go_goleak//:goleak",
1519
],
1620
)

executor/test/executor_issue_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ package explain
1717
import (
1818
"testing"
1919

20+
"github.com/pingcap/failpoint"
21+
"github.com/pingcap/tidb/executor"
2022
"github.com/pingcap/tidb/testkit"
23+
"github.com/stretchr/testify/require"
2124
)
2225

2326
func TestIssue53867(t *testing.T) {
@@ -36,3 +39,24 @@ func TestIssue53867(t *testing.T) {
3639
// Need no panic
3740
tk.MustQuery("select /*+ STREAM_AGG() */ (ref_4.c_k3kss19 / ref_4.c_k3kss19) as c2 from t_bhze93f as ref_4 where (EXISTS (select ref_5.c_wp7o_0sstj as c0 from t_bhze93f as ref_5 where (207007502 < (select distinct ref_6.c_weg as c0 from t_xf1at0 as ref_6 union all (select ref_7.c_xb as c0 from t_b0t as ref_7 where (-16090 != ref_4.c_x393ej_)) limit 1)) limit 1));")
3841
}
42+
43+
func TestIssue60926(t *testing.T) {
44+
store := testkit.CreateMockStore(t)
45+
tk := testkit.NewTestKit(t, store)
46+
47+
tk.MustExec("use test")
48+
tk.MustExec("drop table if exists t1")
49+
tk.MustExec("drop table if exists t2")
50+
tk.MustExec("create table t1 (col0 int, col1 int);")
51+
tk.MustExec("create table t2 (col0 int, col1 int);")
52+
tk.MustExec("insert into t1 values (0, 10), (1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10), (10, 10);")
53+
tk.MustExec("insert into t2 values (0, 5), (0, 5), (1, 5), (2, 5), (2, 5), (3, 5), (4, 5), (5, 5), (5, 5), (6, 5), (7, 5), (8, 5), (8, 5), (9, 5), (9, 5), (10, 5);")
54+
55+
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/executor/join/issue60926", "panic"))
56+
defer func() {
57+
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/executor/join/issue60926"))
58+
}()
59+
executor.IsChildCloseCalledForTest.Store(false)
60+
tk.MustQuery("select * from t1 join (select col0, sum(col1) from t2 group by col0) as r on t1.col0 = r.col0;")
61+
require.True(t, executor.IsChildCloseCalledForTest.Load())
62+
}

0 commit comments

Comments
 (0)