fix bug of read to many bytes

This commit is contained in:
hebo 2019-09-26 08:59:42 +08:00
parent f60f43046d
commit f5b8337638
1 changed files with 14 additions and 16 deletions

View File

@ -12,17 +12,17 @@ import (
)
type MysqlSession struct {
connectionID *string
visitUser *string
visitDB *string
clientHost *string
clientPort int
serverIP *string
serverPort int
stmtBeginTime int64
connectionID *string
visitUser *string
visitDB *string
clientHost *string
clientPort int
serverIP *string
serverPort int
stmtBeginTime int64
// packageOffset int64
beginSeqID int64
endSeqID int64
beginSeqID int64
endSeqID int64
coverRanges *coverRanges
expectReceiveSize int
expectSendSize int
@ -59,7 +59,7 @@ func NewMysqlSession(
queryPieceReceiver: receiver,
closeConn: make(chan bool, 1),
expectReceiveSize: -1,
coverRanges: NewCoverRanges(),
coverRanges: NewCoverRanges(),
ignoreAckID: -1,
sendSize: 0,
pkgCacheLock: sync.Mutex{},
@ -100,7 +100,7 @@ func (ms *MysqlSession) resetBeginTime() {
}
func (ms *MysqlSession) readFromServer(bytes []byte) {
if ms.expectSendSize < 1 {
if ms.expectSendSize < 1 && len(bytes) > 4 {
ms.expectSendSize = extractMysqlPayloadSize(bytes[:4])
contents := bytes[4:]
if ms.prepareInfo != nil && contents[0] == 0 {
@ -115,7 +115,7 @@ func (ms *MysqlSession) checkFinish() bool {
}
checkNode := ms.coverRanges.head.next
if checkNode.end - checkNode.begin == int64(len(ms.cachedStmtBytes)) {
if checkNode.end-checkNode.begin == int64(len(ms.cachedStmtBytes)) {
return true
}
@ -160,7 +160,6 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
ms.beginSeqID = seqID
ms.endSeqID = seqID
if int64(ms.expectReceiveSize) < int64(len(contents)) {
log.Warnf("receive invalid mysql packet")
return
@ -192,7 +191,7 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
if seqOffset+contentSize > int64(len(ms.cachedStmtBytes)) {
// not in a normal mysql packet
log.Debugf("receive an unexpect packet")
ms.clear()
ms.clear()
return
}
@ -204,7 +203,6 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
// ms.expectReceiveSize = ms.expectReceiveSize - int(contentSize)
}
func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
defer ms.clear()