Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Mar 15, 2024
1 parent 1e78561 commit 77d86ec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
my-cnf: |
innodb_log_file_size=256MB
innodb_buffer_pool_size=512MB
max_allowed_packet=16MB
max_allowed_packet=48MB
; TestConcurrent fails if max_connections is too large
max_connections=50
local_infile=1
Expand Down
22 changes: 14 additions & 8 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"compress/zlib"
"fmt"
"io"
"os"
"sync"
)

Expand Down Expand Up @@ -124,13 +123,20 @@ func (c *decompressor) uncompressPacket() error {
uncompressedLength := int(uint32(header[4]) | uint32(header[5])<<8 | uint32(header[6])<<16)
compressionSequence := uint8(header[3])
if debugTrace {
fmt.Fprintf(os.Stderr, "uncompress cmplen=%v uncomplen=%v seq=%v\n",
comprLength, uncompressedLength, compressionSequence)
}
if compressionSequence != c.mc.compressSequence {
return ErrPktSync
}
c.mc.compressSequence++
c.mc.cfg.Logger.Print(
fmt.Sprintf("uncompress cmplen=%v uncomplen=%v pkt_cmp_seq=%v expected_cmp_seq=%v\n",
comprLength, uncompressedLength, compressionSequence, c.mc.sequence))
}
if compressionSequence != c.mc.sequence {
// return ErrPktSync
// server may return error packet (e.g. 1153 Got a packet bigger than 'max_allowed_packet' bytes)
// before receiving all packets from client. In this case, seqnr is younger than expected.
c.mc.cfg.Logger.Print(
fmt.Sprintf("[warn] unexpected cmpress seq nr: expected %v, got %v",
c.mc.sequence, compressionSequence))
}
c.mc.sequence = compressionSequence + 1
c.mc.compressSequence = c.mc.sequence

comprData, err := c.mc.buf.readNext(comprLength)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,8 @@ func TestLongData(t *testing.T) {
var rows *sql.Rows

// Long text data
const nonDataQueryLen = 28 // length query w/o value
// const nonDataQueryLen = 28 // length query w/o value + compress header
const nonDataQueryLen = 100
inS := in[:maxAllowedPacketSize-nonDataQueryLen]
dbt.mustExec("INSERT INTO test VALUES('" + inS + "')")
rows = dbt.mustQuery("SELECT value FROM test")
Expand Down
22 changes: 8 additions & 14 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,24 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
if cerr := mc.canceled.Value(); cerr != nil {
return nil, cerr
}
// debug.PrintStack()
if debugTrace {
debug.PrintStack()
}
mc.cfg.Logger.Print(err)
mc.Close()
return nil, ErrInvalidConn
}

// packet length [24 bit]
pktLen := int(uint32(data[0]) | uint32(data[1])<<8 | uint32(data[2])<<16)
if debugTrace {
mc.cfg.Logger.Print(fmt.Sprintf("readPacket: packet seq = %d, mc.sequence = %d", data[3], mc.sequence))
}

// check packet sync [8 bit]
if data[3] != mc.sequence {
if debugTrace {
debug.PrintStack()
if !mc.compress { // MySQL and MariaDB doesn't check packet nr in compressed packet.
// check packet sync [8 bit]
if data[3] != mc.sequence {
mc.cfg.Logger.Print(fmt.Sprintf("[warn] unexpected seq nr: expected %v, got %v", mc.sequence, data[3]))
}
mc.Close()
if data[3] > mc.sequence {
return nil, ErrPktSyncMul
}
return nil, ErrPktSync
mc.sequence++
}
mc.sequence++

// packets with length 0 terminate a previous packet which is a
// multiple of (2^24)-1 bytes long
Expand Down

0 comments on commit 77d86ec

Please sign in to comment.