From 2074fbab5f4f5fca70af66061af91708098b4f22 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 26 Nov 2021 14:38:44 +0100 Subject: [PATCH 1/2] Fix for regression of adding port to processlist cc.PeerHost() has been called before, but only returns "" for port on second call. --- server/conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/conn.go b/server/conn.go index f74c00a5550cc..31ccba25cf881 100644 --- a/server/conn.go +++ b/server/conn.go @@ -888,7 +888,7 @@ func (cc *clientConn) checkAuthPlugin(ctx context.Context, resp *handshakeRespon func (cc *clientConn) PeerHost(hasPassword string) (host, port string, err error) { if len(cc.peerHost) > 0 { - return cc.peerHost, "", nil + return cc.peerHost, cc.peerPort, nil } host = variable.DefHostname if cc.isUnixSocket { From 4fc465a4d753e6060c1f8c529d435ad6e379cc3a Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 26 Nov 2021 15:48:14 +0100 Subject: [PATCH 2/2] Added missing test, which allowed the regression to happen --- server/server_test.go | 6 +++++- server/tidb_test.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/server_test.go b/server/server_test.go index 210e58caed3f8..f9d22e866458a 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -779,7 +779,7 @@ func (cli *testServerClient) runTestLoadDataForListColumnPartition2(t *testing.T }) } -func (cli *testServerClient) checkRows(t *testing.T, rows *sql.Rows, expectedRows ...string) { +func (cli *testServerClient) Rows(t *testing.T, rows *sql.Rows) []string { buf := bytes.NewBuffer(nil) result := make([]string, 0, 2) for rows.Next() { @@ -806,7 +806,11 @@ func (cli *testServerClient) checkRows(t *testing.T, rows *sql.Rows, expectedRow } result = append(result, buf.String()) } + return result +} +func (cli *testServerClient) checkRows(t *testing.T, rows *sql.Rows, expectedRows ...string) { + result := cli.Rows(t, rows) require.Equal(t, strings.Join(expectedRows, "\n"), strings.Join(result, "\n")) } diff --git a/server/tidb_test.go b/server/tidb_test.go index 01a19d70df6d1..2536752d3b0fe 100644 --- a/server/tidb_test.go +++ b/server/tidb_test.go @@ -528,6 +528,9 @@ func TestSocketAndIp(t *testing.T) { cli.checkRows(t, rows, "user1@127.0.0.1") rows = dbt.MustQuery("show grants") cli.checkRows(t, rows, "GRANT USAGE ON *.* TO 'user1'@'%'\nGRANT SELECT ON test.* TO 'user1'@'%'") + rows = dbt.MustQuery("select host from information_schema.processlist where user = 'user1'") + records := cli.Rows(t, rows) + require.Contains(t, records[0], ":", "Missing : in is.processlist") }) // Test with unix domain socket file connection with all hosts cli.runTests(t, func(config *mysql.Config) {