Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pretty66 authored Nov 16, 2021
2 parents 702519c + 95d05ef commit 2cb006b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
28 changes: 16 additions & 12 deletions client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,25 @@ func (c *Conn) readInitialHandshake() error {
c.capability = uint32(binary.LittleEndian.Uint16(data[pos:pos+2]))<<16 | c.capability
pos += 2

// skip auth data len or [00]
// auth_data is end with 0x00, min data length is 13 + 8 = 21
// ref to https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake
maxAuthDataLen := 21
if c.capability&CLIENT_PLUGIN_AUTH != 0 && int(data[pos]) > maxAuthDataLen {
maxAuthDataLen = int(data[pos])
}

// skip reserved (all [00])
pos += 10 + 1

// The documentation is ambiguous about the length.
// The official Python library uses the fixed length 12
// mysql-proxy also use 12
// which is not documented but seems to work.
c.salt = append(c.salt, data[pos:pos+12]...)
pos += 13
// auth plugin
if end := bytes.IndexByte(data[pos:], 0x00); end != -1 {
c.authPluginName = string(data[pos : pos+end])
} else {
c.authPluginName = string(data[pos:])
// auth_data is end with 0x00, so we need to trim 0x00
resetOfAuthDataEndPos := pos + maxAuthDataLen - 8 - 1
c.salt = append(c.salt, data[pos:resetOfAuthDataEndPos]...)

// skip reset of end pos
pos = resetOfAuthDataEndPos + 1

if c.capability&CLIENT_PLUGIN_AUTH != 0 {
c.authPluginName = string(data[pos : len(data)-1])
}
}

Expand Down
9 changes: 4 additions & 5 deletions replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,10 @@ func (b *BinlogSyncer) onStream(s *BinlogStreamer) {
s.closeWithError(err)
return
case EOF_HEADER:
// Refer http://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html
// In the MySQL client/server protocol, EOF and OK packets serve the same purpose.
// Some users told me that they received EOF packet here, but I don't know why.
// So we only log a message and retry ReadPacket.
log.Info("receive EOF packet, retry ReadPacket")
// refer to https://dev.mysql.com/doc/internals/en/com-binlog-dump.html#binlog-dump-non-block
// when COM_BINLOG_DUMP command use BINLOG_DUMP_NON_BLOCK flag,
// if there is no more event to send an EOF_Packet instead of blocking the connection
log.Info("receive EOF packet, no more binlog event now.")
continue
default:
log.Errorf("invalid stream header %c", data[0])
Expand Down

0 comments on commit 2cb006b

Please sign in to comment.