Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server, tidb-server: improve unix socket handling #8836

Merged
merged 17 commits into from Jan 9, 2019

Conversation

@morgo
Copy link
Contributor

commented Dec 26, 2018

What problem does this PR solve?

Fixes #8459

What is changed and how it works?

  • Allows server to listen on both unix socket and TCP at the same time
  • Removes socket file on server clean exit
  • Handles the error / refuses to start if the socket file is already in use.
  • Supports the case that neither a socket file or tcp (host,port) are specified

Check List

Tests

  • Manual test

I'm not actually sure how to write tests to validate it, but happy to do so with pointers.

Code changes

  • Has exported function/method change

Side effects

  • Possible performance regression (socket access may be slower)
  • Breaking backward compatibility (socket access when both tcp and socket enabled will authenticate like tcp connections)
  • Increased code complexity

Related changes

  • Need to be included in the release note

This change is Reviewable

morgo added 2 commits Dec 26, 2018
Cleanup socket file on exit
Handle error of socket file exists
Support both socket and tcp via redirection
Support case neither socket or tcp specified
@morgo morgo requested a review from jackysp Dec 26, 2018
@morgo morgo requested a review from coocood Dec 26, 2018
@morgo

This comment has been minimized.

Copy link
Contributor Author

commented Dec 26, 2018

PTAL @coocood, @jackysp. Thx!

@morgo

This comment has been minimized.

Copy link
Contributor Author

commented Dec 26, 2018

/run-all-tests

@morgo morgo changed the title server, *: improve unix socket handling server, tidb-server: improve unix socket handling Dec 26, 2018
@morgo

This comment has been minimized.

Copy link
Contributor Author

commented Dec 26, 2018

/run-all-tests

@jackysp

This comment has been minimized.

Copy link
Member

commented Dec 27, 2018

@jackysp jackysp requested a review from tiancaiamao Dec 27, 2018
Copy link
Contributor

left a comment

Looks like a good idea.

server/server.go Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
tidb-server/main.go Outdated Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
}
}

func (s *Server) handleForwardedConnection(uconn net.Conn, addr string) {

This comment has been minimized.

Copy link
@gregwebs

gregwebs Dec 28, 2018

Contributor

Rather than logging warnings, I would return an error and have the caller deal with it (the caller can log or retry).

This comment has been minimized.

Copy link
@morgo

morgo Dec 28, 2018

Author Contributor

In this case, handleForwardedConnection is an async call (called as a go routine), so I think it is important to handle its own?

This comment has been minimized.

Copy link
@gregwebs

gregwebs Dec 28, 2018

Contributor

Right, the caller would expand to an anonymous function that calls this function and does something with the error.

server/server.go Outdated Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
@morgo morgo added the status/DNM label Dec 28, 2018
@morgo

This comment has been minimized.

Copy link
Contributor Author

commented Dec 28, 2018

I am not sure if I tested it wrong yesterday, but I can't seem to get the server to listen on tcp + socket. I tried:

make server && ./bin/tidb-server -socket /tmp/tidb.sock &
mysql --no-defaults -S /tmp/tidb.sock 

The mysql client just hangs until I control + c, then get the error:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 95

I appreciate any feedback if you know what's wrong :(

@coocood

This comment has been minimized.

Copy link
Member

commented Dec 28, 2018

The listener seems still not closed in Server.Close method.

morgo added 3 commits Dec 29, 2018
@morgo morgo removed the status/DNM label Dec 29, 2018
morgo added 2 commits Dec 29, 2018
server/tidb_test.go Outdated Show resolved Hide resolved
server/server.go Show resolved Hide resolved
@codecov-io

This comment has been minimized.

Copy link

commented Jan 3, 2019

Codecov Report

❗️ No coverage uploaded for pull request base (master@78a51a4). Click here to learn what that means.
The diff coverage is 69.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #8836   +/-   ##
=========================================
  Coverage          ?   67.53%           
=========================================
  Files             ?      363           
  Lines             ?    75142           
  Branches          ?        0           
=========================================
  Hits              ?    50746           
  Misses            ?    19918           
  Partials          ?     4478
Impacted Files Coverage Δ
server/server.go 56.85% <69.44%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78a51a4...207900a. Read the comment docs.

morgo added 4 commits Jan 5, 2019
@coocood

This comment has been minimized.

Copy link
Member

commented Jan 7, 2019

LGTM

@morgo morgo added the status/LGT1 label Jan 7, 2019
@jackysp

This comment has been minimized.

Copy link
Member

commented Jan 8, 2019

/run-all-tests

@morgo

This comment has been minimized.

Copy link
Contributor Author

commented Jan 8, 2019

/run-all-tests

@jackysp

This comment has been minimized.

Copy link
Member

commented Jan 9, 2019

/run-unit-test

@jackysp
jackysp approved these changes Jan 9, 2019
Copy link
Member

left a comment

LGTM

@jackysp jackysp merged commit 692693a into pingcap:master Jan 9, 2019
12 checks passed
12 checks passed
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/common-test job succeeded
Details
idc-jenkins-ci-tidb/integration-common-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-compatibility-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-ddl-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/mybatis-test job succeeded
Details
idc-jenkins-ci-tidb/sqllogic-test-1 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/sqllogic-test-2 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/unit-test Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
@morgo morgo deleted the morgo:socket branch Jan 9, 2019
@morgo morgo referenced this pull request Mar 6, 2019
5 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.