go-mysql-org / go-mysql

a powerful mysql toolset with Go
MIT License
4.52k stars 967 forks source link

fixing bad connection error when reading large compressed packets #863

Closed dvilaverde closed 2 months ago

dvilaverde commented 2 months ago

This is a fix for https://github.com/go-mysql-org/go-mysql/issues/862

jnewmano commented 2 months ago

I tried running your fork and got a panic, I'll work on getting a test case that I can share to reproduce.

[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x49d587]

goroutine 1 [running]:
io.ReadAtLeast({0x0, 0x0}, {0xc000000000, 0x4, 0x4000}, 0x4)
        /usr/local/go/src/io/io.go:335 +0x67
github.com/go-mysql-org/go-mysql/packet.(*Conn).copyN(0xc00013e070, {0x8bd0e0, 0xc001f0e030}, {0x7fe96f835c00, 0xc00007a550}, 0x1ac000?)
        /go/pkg/mod/github.com/dvilaverde/go-mysql@v0.0.0-20240503125055-5895dda79aff/packet/conn.go:209 +0x206
github.com/go-mysql-org/go-mysql/packet.(*Conn).ReadPacketTo(0xc00013e070, {0x8bd0e0, 0xc001f0e000})
        /go/pkg/mod/github.com/dvilaverde/go-mysql@v0.0.0-20240503125055-5895dda79aff/packet/conn.go:237 +0xc5
github.com/go-mysql-org/go-mysql/packet.(*Conn).ReadPacketReuseMem(0xc00013e070, {0xc000b8e000, 0x1570cb, 0x1ac000})
        /go/pkg/mod/github.com/dvilaverde/go-mysql@v0.0.0-20240503125055-5895dda79aff/packet/conn.go:121 +0x165
github.com/go-mysql-org/go-mysql/client.(*Conn).readResultRows(0xc0000a0340, 0xc000106060, 0x1)
dvilaverde commented 2 months ago

I tried running your fork and got a panic, I'll work on getting a test case that I can share to reproduce.

[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x49d587]

goroutine 1 [running]:
io.ReadAtLeast({0x0, 0x0}, {0xc000000000, 0x4, 0x4000}, 0x4)
        /usr/local/go/src/io/io.go:335 +0x67
github.com/go-mysql-org/go-mysql/packet.(*Conn).copyN(0xc00013e070, {0x8bd0e0, 0xc001f0e030}, {0x7fe96f835c00, 0xc00007a550}, 0x1ac000?)
        /go/pkg/mod/github.com/dvilaverde/go-mysql@v0.0.0-20240503125055-5895dda79aff/packet/conn.go:209 +0x206
github.com/go-mysql-org/go-mysql/packet.(*Conn).ReadPacketTo(0xc00013e070, {0x8bd0e0, 0xc001f0e000})
        /go/pkg/mod/github.com/dvilaverde/go-mysql@v0.0.0-20240503125055-5895dda79aff/packet/conn.go:237 +0xc5
github.com/go-mysql-org/go-mysql/packet.(*Conn).ReadPacketReuseMem(0xc00013e070, {0xc000b8e000, 0x1570cb, 0x1ac000})
        /go/pkg/mod/github.com/dvilaverde/go-mysql@v0.0.0-20240503125055-5895dda79aff/packet/conn.go:121 +0x165
github.com/go-mysql-org/go-mysql/client.(*Conn).readResultRows(0xc0000a0340, 0xc000106060, 0x1)

That would be great. I'll take a look when you provide that.

dvilaverde commented 2 months ago

I've pushed one more change that may address the panic you found in your testing. There was a gap that could cause io.ReadAtLeast to be called with a nil reader when the compressed packet header had an uncompressed length with value zero.

Also not sure why golangci-lint checks are failing now, they pass when i run locally using version 1.57.2. The GitHub Action is using 1.58.0 and when i tried with that version it never completes and seems to consume 60gb+ of my system memory.

jnewmano commented 2 months ago

The latest commit fixed the panic I was seeing. Thank you.

dvilaverde commented 2 months ago

Fixed the golangci-lint issue as well. The latest version 1.58.0 removed 3 linters, so i removed those from the config file.

jnewmano commented 2 months ago

One of the commits after 22dbb42 has led to broken connections when using compression with the error message invalid compressed sequence 2 != 1

dvilaverde commented 2 months ago

One of the commits after 22dbb42 has led to broken connections when using compression with the error message invalid compressed sequence 2 != 1

Do you happen to have a way to reproduce? Any other info that could help in diagnosing the issue?

jnewmano commented 2 months ago

One of the commits after 22dbb42 has led to broken connections when using compression with the error message invalid compressed sequence 2 != 1

Do you happen to have a way to reproduce? Any other info that could help in diagnosing the issue?

I'll get more information together and open an issue.

jnewmano commented 2 months ago

One of the commits after 22dbb42 has led to broken connections when using compression with the error message invalid compressed sequence 2 != 1

Do you happen to have a way to reproduce? Any other info that could help in diagnosing the issue?

Details posted in issue #871