Skip to content

Commit

Permalink
server: don't interrupt when nodelay executed (#11135)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored Jul 10, 2019
1 parent f409f0b commit 8c20289
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,9 @@ func (cc *clientConn) handleQuery(ctx context.Context, sql string) (err error) {
return err
}
status := atomic.LoadInt32(&cc.status)
if status == connStatusShutdown || status == connStatusWaitShutdown {
if rs != nil && (status == connStatusShutdown || status == connStatusWaitShutdown) {
killConn(cc)
return errors.New("killed by another connection")
return executor.ErrQueryInterrupted
}
if rs != nil {
if len(rs) == 1 {
Expand Down
34 changes: 31 additions & 3 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/util/arena"
"github.com/pingcap/tidb/util/testleak"
Expand All @@ -38,7 +40,7 @@ type ConnTestSuite struct {
store kv.Storage
}

var _ = Suite(ConnTestSuite{})
var _ = Suite(&ConnTestSuite{})

func (ts *ConnTestSuite) SetUpSuite(c *C) {
testleak.BeforeTest()
Expand Down Expand Up @@ -420,7 +422,7 @@ func (ts *ConnTestSuite) TestConnExecutionTimeout(c *C) {
c.Assert(err, IsNil)

err = cc.handleQuery(context.Background(), "select * FROM testTable2 WHERE SLEEP(1);")
c.Assert(err, NotNil)
c.Assert(err, IsNil)

_, err = se.Execute(context.Background(), "set @@max_execution_time = 0;")
c.Assert(err, IsNil)
Expand All @@ -429,7 +431,33 @@ func (ts *ConnTestSuite) TestConnExecutionTimeout(c *C) {
c.Assert(err, IsNil)

err = cc.handleQuery(context.Background(), "select /*+ MAX_EXECUTION_TIME(100)*/ * FROM testTable2 WHERE SLEEP(1);")
c.Assert(err, NotNil)
c.Assert(err, IsNil)

c.Assert(failpoint.Disable("github.com/pingcap/tidb/server/FakeClientConn"), IsNil)
}

type mockTiDBCtx struct {
TiDBContext
rs []ResultSet
err error
}

func (c *mockTiDBCtx) Execute(ctx context.Context, sql string) ([]ResultSet, error) {
return c.rs, c.err
}

func (c *mockTiDBCtx) GetSessionVars() *variable.SessionVars {
return &variable.SessionVars{}
}

func (ts *ConnTestSuite) TestShutDown(c *C) {
cc := &clientConn{}

// mock delay response
cc.ctx = &mockTiDBCtx{rs: []ResultSet{&tidbResultSet{}}, err: nil}
// set killed flag
cc.status = connStatusShutdown
// assert ErrQueryInterrupted
err := cc.handleQuery(context.Background(), "dummy")
c.Assert(err, Equals, executor.ErrQueryInterrupted)
}

0 comments on commit 8c20289

Please sign in to comment.