Skip to content

Commit

Permalink
server: set connection to TCP socket when unix and TCP used (#23463) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored May 11, 2021
1 parent b4c66ac commit 62dace6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ func (s *Server) newConn(conn net.Conn) *clientConn {
return cc
}

// isUnixSocket should ideally be a function of clientConnection!
// But currently since unix-socket connections are forwarded to TCP when the server listens on both, it can really only be accurate on a server-level.
// If the server is listening on both, it *must* return FALSE for remote-host authentication to be performed correctly. See #23460.
func (s *Server) isUnixSocket() bool {
return s.cfg.Socket != ""
return s.cfg.Socket != "" && s.cfg.Port == 0
}

func (s *Server) forwardUnixSocketToTCP() {
Expand Down
3 changes: 3 additions & 0 deletions server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (ts *tidbTestSuite) TestStatusAPIWithTLS(c *C) {
cli.statusPort = getPortFromTCPAddr(server.statusListener.Addr())
go server.Run()
time.Sleep(time.Millisecond * 100)
c.Assert(server.isUnixSocket(), IsFalse) // If listening on tcp-only, return FALSE

// https connection should work.
ts.runTestStatusAPI(c)
Expand Down Expand Up @@ -348,6 +349,7 @@ func (ts *tidbTestSuite) TestSocketForwarding(c *C) {
cli.port = getPortFromTCPAddr(server.listener.Addr())
go server.Run()
time.Sleep(time.Millisecond * 100)
c.Assert(server.isUnixSocket(), IsFalse) // If listening on both, return FALSE
defer server.Close()

cli.runTestRegression(c, func(config *mysql.Config) {
Expand All @@ -371,6 +373,7 @@ func (ts *tidbTestSuite) TestSocket(c *C) {
c.Assert(err, IsNil)
go server.Run()
time.Sleep(time.Millisecond * 100)
c.Assert(server.isUnixSocket(), IsTrue) // If listening on socket-only, return TRUE
defer server.Close()

//a fake server client, config is override, just used to run tests
Expand Down

0 comments on commit 62dace6

Please sign in to comment.