go-sql-driver / mysql

Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
https://pkg.go.dev/github.com/go-sql-driver/mysql
Mozilla Public License 2.0
14.46k stars 2.3k forks source link

Return timeout error instead of Invalid connection err when read packet network timeout #1544

Closed Jun10ng closed 7 months ago

Jun10ng commented 7 months ago

https://github.com/go-sql-driver/mysql/blob/743e263bab87912dfb61789f36c21d9685887c76/packets.go#L28C1-L41C1

I saw that my application would return invalid connection error when using mysql, I thought it was caused by using invalid expired mysql connection, but when I search the network logs, I found the logs of reading packet return timeout, as below.

  1. I think driver should return an error like timeout instead of invalid connection.
  2. In this case, shall we wait the delay packet or just fail it ?

    [mysql] 20xx/xx/xx 12:11:01 packets.go:36: read tcp xx.xx.xx.xx:3306: i/o timeout
methane commented 7 months ago
  • I think driver should return an error like timeout instead of invalid connection.

It is breaking change. It requires strong reason than "I think".

2. In this case, shall we wait the delay packet or just fail it ?

I don't know why you see timeout because no reproduce step.

Jun10ng commented 7 months ago
  • I think driver should return an error like timeout instead of invalid connection.

It is breaking change. It requires strong reason than "I think".

  1. In this case, shall we wait the delay packet or just fail it ?

I don't know why you see timeout because no reproduce step.

  • You may need fix your network or server configuration.
  • You may need to remove readTimeout client setting.

Thanks for the reply.

Jun10ng commented 7 months ago

My confusion is that the connection Application using is not invalid, but the logs and errors show that it's an invalid connection.

methane commented 7 months ago

Connection facing timeout error is invalid connection.

Jun10ng commented 7 months ago

Connection facing timeout error is invalid connection.

That's a good point. thanks.