From ae8ada408fed053ee8d4a04b3f54cabc39563894 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 1 Jul 2019 16:10:10 +0800 Subject: [PATCH] *: fix oom action cancel bug (#10993) --- executor/executor_test.go | 19 +++++++++++++++++++ store/tikv/coprocessor.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index a5fe033ecfdb1..2b5aaa145f229 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -60,6 +60,7 @@ import ( "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/admin" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/logutil" @@ -3958,6 +3959,24 @@ func (s *testOOMSuite) TestDistSQLMemoryControl(c *C) { tk.Se.GetSessionVars().MemQuotaDistSQL = -1 } +func (s *testSuite) TestOOMPanicAction(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a int primary key, b double);") + tk.MustExec("insert into t values (1,1)") + sm := &mockSessionManager1{ + PS: make([]*util.ProcessInfo, 0), + } + tk.Se.SetSessionManager(sm) + s.domain.ExpensiveQueryHandle().SetSessionManager(sm) + config.GetGlobalConfig().OOMAction = config.OOMActionCancel + tk.MustExec("set @@tidb_mem_quota_query=1;") + err := tk.QueryToErr("select sum(b) from t group by a;") + c.Assert(err, NotNil) + c.Assert(err.Error(), Matches, "Out Of Memory Quota!.*") +} + type oomCapturer struct { zapcore.Core tracker string diff --git a/store/tikv/coprocessor.go b/store/tikv/coprocessor.go index a0c7e37eb084e..251ec6796e8d6 100644 --- a/store/tikv/coprocessor.go +++ b/store/tikv/coprocessor.go @@ -620,7 +620,7 @@ func (worker *copIteratorWorker) handleTask(bo *Backoffer, task *copTask, respCh zap.Stack("stack trace")) resp := &copResponse{err: errors.Errorf("%v", r)} // if panic has happened, set checkOOM to false to avoid another panic. - worker.sendToRespCh(resp, task.respChan, false) + worker.sendToRespCh(resp, respCh, false) } }() remainTasks := []*copTask{task}