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: compatible to old handshake protocol #8812

Merged
merged 6 commits into from
Dec 26, 2018

Conversation

imtbkcat
Copy link

@imtbkcat imtbkcat commented Dec 25, 2018

What problem does this PR solve?

When using HAProxy connect to TiDB server, option mysql-check user root will cause handshake fail error because TiDB do not support Protocol::HandshakeResponse320

What is changed and how it works?

ParserProtocol::HandshakeResponse320 to Protocol::HandshakeResponse41, which is supported by TiDB.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

This change is Reviewable

@imtbkcat
Copy link
Author

/run-all-tests

@imtbkcat
Copy link
Author

/run-unit-test

@lysu lysu self-assigned this Dec 25, 2018
@imtbkcat
Copy link
Author

/run-all-tests

server/conn.go Outdated
var resp handshakeResponse41

pos, err := parseHandshakeResponseHeader(&resp, data)
if err != nil {
return errors.Trace(err)
if err == mysql.ErrMalformPacket {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protocol::HandshakeResponse41:
Handshake Response Packet sent by 4.1+ clients supporting CLIENT_PROTOCOL_41 capability, if the server announced it in its Initial Handshake Packet. Otherwise (talking to an old server) the Protocol::HandshakeResponse320 packet must be used.

https://dev.mysql.com/doc/internals/en/connection-phase-packets.html

@imtbkcat can we direct use CLIENT_PROTOCOL_41 capability to decide use 41 or 32, because our Initial Handshake Packet always contain ClientProtocol41?

parse handshake twice has risk

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@imtbkcat imtbkcat added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 26, 2018
server/conn.go Outdated
// parseHandshakeResponseHeader parses the common header of SSLRequest and HandshakeResponse41.
func parseHandshakeResponseHeader(packet *handshakeResponse41, data []byte) (parsedBytes int, err error) {
// Ensure there are enough data to read:
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest
if len(data) < 4+4+1+23 {
log.Errorf("Got malformed handshake response, packet data: %v", data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add it back if we don't parse protocol 41 first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackysp addressed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jackysp
Copy link
Member

jackysp commented Dec 26, 2018

/run-all-tests

yu34po pushed a commit to yu34po/tidb that referenced this pull request Jan 2, 2019
@morgo morgo mentioned this pull request Sep 2, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants