From 3171b98d16da6f77dd884a1f7b4b7543a8135d60 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Thu, 4 Feb 2021 20:25:49 -0700 Subject: [PATCH 1/4] server: return OK when there is no stmt --- server/conn.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/conn.go b/server/conn.go index b87b62f6f77ac..b0d46538958e9 100644 --- a/server/conn.go +++ b/server/conn.go @@ -1387,6 +1387,10 @@ func (cc *clientConn) handleQuery(ctx context.Context, sql string) (err error) { return err } + if len(stmts) == 0 { + return cc.writeOK(ctx) + } + var appendMultiStmtWarning bool if len(stmts) > 1 { From dd89829fd0458143e8f6f944a84846d7fd7189e0 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Thu, 4 Feb 2021 21:19:20 -0700 Subject: [PATCH 2/4] Add tests for empty query --- server/server_test.go | 14 ++++++++++++++ server/tidb_test.go | 1 + 2 files changed, 15 insertions(+) diff --git a/server/server_test.go b/server/server_test.go index 411230b252c7e..98ad22e911465 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1114,6 +1114,20 @@ func (cli *testServerClient) runTestIssue3680(c *C) { c.Assert(err.Error(), Equals, "Error 1045: Access denied for user 'non_existing_user'@'127.0.0.1' (using password: NO)") } +func (cli *testServerClient) runTestIssue22646(c *C) { + cli.runTests(c, nil, func(dbt *DBTest) { + c1 := make(chan string, 1) + go func() { + dbt.mustExec(``) // empty query. + c1 <- "success" + }() + select { + case <-time.After(4 * time.Second): + panic("read empty query statement timed out.") + } + }) +} + func (cli *testServerClient) runTestIssue3682(c *C) { cli.runTests(c, nil, func(dbt *DBTest) { dbt.mustExec(`CREATE USER 'issue3682'@'%' IDENTIFIED BY '123';`) diff --git a/server/tidb_test.go b/server/tidb_test.go index 097c7f14d451e..9290cd35b6d75 100644 --- a/server/tidb_test.go +++ b/server/tidb_test.go @@ -176,6 +176,7 @@ func (ts *tidbTestSuite) TestIssues(c *C) { c.Parallel() ts.runTestIssue3662(c) ts.runTestIssue3680(c) + ts.runTestIssue22646(c) } func (ts *tidbTestSuite) TestDBNameEscape(c *C) { From 2ae7f4d53a952ef5e560da23635bc458bd3c7f63 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Thu, 4 Feb 2021 21:48:24 -0700 Subject: [PATCH 3/4] extend timeout to 30s --- server/server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server_test.go b/server/server_test.go index 98ad22e911465..9d38fcf1a1d4e 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1122,7 +1122,7 @@ func (cli *testServerClient) runTestIssue22646(c *C) { c1 <- "success" }() select { - case <-time.After(4 * time.Second): + case <-time.After(30 * time.Second): panic("read empty query statement timed out.") } }) From c24a4dde0a0a4657095fdda87ddc7df06906b7d1 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Thu, 4 Feb 2021 22:02:22 -0700 Subject: [PATCH 4/4] fix timeout --- server/server_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/server_test.go b/server/server_test.go index 9d38fcf1a1d4e..f70c8e2fbda38 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1122,6 +1122,8 @@ func (cli *testServerClient) runTestIssue22646(c *C) { c1 <- "success" }() select { + case res := <-c1: + fmt.Println(res) case <-time.After(30 * time.Second): panic("read empty query statement timed out.") }