mysql
mysql copied to clipboard
Should return i/o read/write timeout error, not just invalid connection(ErrInvalidConn)
Issue description
Should return i/o read/write timeout error, not just invalid connection(ErrInvalidConn).
Example code
db, _ = sql.Open("mysql", "root:xxxx@tcp(127.0.0.1:3306)/xx_db?charset=utf8mb4&readTimeout=2s&timeout=2s&writeTimeout=2s")
_, err := db.Query("select sleep(3)")
// doCheckError(err)
defer db.Close()
Error log
If you have an error log, please paste it here.
Configuration
Driver version (or git SHA):
Go version: run go version
in your console
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
+1
You had not describe why "should".
This is causing troubles:
// create a listener which does not accept
listener, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", p))
if err != nil {
t.Fatal(err)
}
defer listener.Close()
t.Run("test open", func(t *testing.T) {
db, err := sql.Open("mysql", fmt.Sprintf("test@tcp(localhost:%d)/test?timeout=1s", p))
assert.NoError(t, err)
assert.ErrorContains(t, db.Ping(), "deadline exceeded")
})
Here you see we have a listener, which does accept - this is btw the case when your port is behind a firewall and no access is allowed.
If I use this driver and set timeout=10s
and try to connect to a database which is behind a firewall - or a listener which does not accept (ACK) I would expect the a call to Ping() to fail after 10s - it just hangs
@timo-klarshift your case is not relating to this issue.
Your example code doesn't accept connection. But your OS accept some connections.
timeout=1s
doesn't cause error because mysql driver succeeded to connect.
And there are no timeout for Ping in your code. That's why your example hangs up.
You had not describe why "should".
if there is timeout Error, we can diff it from such as closed connection. mostly maybe cause by a slow sql
How is it important to write a robust application? I can find slow sql without relying on i/o error.
Just a case example, it would be better if the error types are different.