go-mysql-org / go-mysql

a powerful mysql toolset with Go
MIT License
4.58k stars 976 forks source link

Enabling compression on client connection results in "connection was bad" error #862

Closed dvilaverde closed 4 months ago

dvilaverde commented 5 months ago

When compression is enabled on the client my application fails with connection was bad, the nested exception is:

io.CopyN failed. err unexpected EOF, copied 0, expected 29

But when disabling compression the application works correctly.

Repro Steps

Start MariaDB in Docker:

docker run --rm -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mariadb:10.3.39

Create the DB and table found in the attached file

db_schema.txt

Run this test:

import (
  "github.com/go-mysql-org/go-mysql/client"
  "github.com/go-mysql-org/go-mysql/mysql"
  "github.com/stretchr/testify/assert"
)

func TestServer_ShowFieldTable1(t *testing.T) {
    a := assert.New(t)

    c, err := client.Connect("localhost:3306", "root", "root", "mydb", func(conn *client.Conn) {
        conn.SetCapability(mysql.CLIENT_COMPRESS) // Disable compression and the test will pass
    })
    a.NoError(err)

    execute, err := c.Execute("SHOW FIELDS FROM mydb.table1")
    if a.NoError(err) {
        rs := execute.Resultset
        a.Equal(575, len(rs.RowDatas))
    }
}
dvilaverde commented 5 months ago

Some more context in case it helps. I notice that setting net_buffer_length on the server causes the above test case to pass, for example:

set global net_buffer_length=32768;

then resetting it lot the original value will revert to the previous failing behavior.

set global net_buffer_length=16384;
dveeden commented 5 months ago

Thanks for the bugreport. I'll try to reproduce this.

dvilaverde commented 5 months ago

I've created a PR that seems to fix this in my fork: https://github.com/go-mysql-org/go-mysql/pull/863

dvilaverde commented 4 months ago

Merged https://github.com/go-mysql-org/go-mysql/pull/863