Issues with GET_LOCK and a too long lock name on MySQL 5.7
When running the GET_LOCK() SQL statement with a too long lock name via db.Exec on a MySQL 5.7 the statement seems to hang.
The maximum name of the name of the lock given to GET_LOCK() in MySQL 5.7 is shorter than the one in MySQL 5.6. So I would expect an error to be returned, but this doesn't happen.
It looks like it gets a ErrBadConn and then retries a few times as described on https://www.vividcortex.com/blog/2015/01/19/gos-connection-pool-retries-and-timeouts/ So it probably takes 10*timeout before it really returns.
This is the behaviour of a mysql session:
mysql-5.7> SELECT GET_LOCK('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', '5');
ERROR 3057 (42000): Incorrect user-level lock name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Testcase:
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main () {
db, err := sql.Open("mysql", "user:host@tcp(127.0.0.1:3306)/mydb")
if err != nil { panic(err.Error()) }
res, err := db.Exec("SELECT VERSION()")
if err != nil { panic(err.Error()) } else { println(res) }
res, err = db.Exec("SELECT VERSION()")
if err != nil { panic(err.Error()) } else { println(res) }
res, err = db.Exec("SELECT GET_LOCK('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', '5')")
if err != nil { panic(err.Error()) } else { println(res) }
res, err = db.Exec("SELECT VERSION()")
if err != nil { panic(err.Error()) } else { println(res) }
res, err = db.Exec("SELECT VERSION()")
if err != nil { panic(err.Error()) } else { println(res) }
}
Current behavior: The testcase will run the first two SELECT VERSION() statements and print res and than hangs.
Expected behavior: Quickly return an error
The full output:
$ ./go-mysql57-getlock
(0x7fce3f7815e8,0xc820012600)
(0x7fce3f7815e8,0xc820012620)
[MySQL] 2015/11/13 13:21:51 packets.go:32: unexpected EOF
[MySQL] 2015/11/13 13:26:52 packets.go:32: unexpected EOF
[MySQL] 2015/11/13 13:31:52 packets.go:32: unexpected EOF
panic: driver: bad connection
goroutine 1 [running]:
main.main()
/home/dvaneeden/dev/go-mysql57-getlock/go-mysql57-getlock.go:16 +0x35e
goroutine 5 [chan receive]:
database/sql.(*DB).connectionOpener(0xc8200988c0)
/usr/local/go/src/database/sql/sql.go:634 +0x45
created by database/sql.Open
/usr/local/go/src/database/sql/sql.go:481 +0x336
readUntilEOF() is doing a mc.readPacket() which waits..
Wireshark shows this: 4 packets are returned after the Request: Packet 1: number of fields: 1 Packet 2: Column name (the original query) Packet 3: EOF marker Packet 4: Error code and SQL state
I expect that the go-sql-driver expects the EOF marker to be the last packet?
Any update on this? Maybe an idea about how this should be fixed?
I feel that this should be closed since MySQL 5.7 has reached its end of life.
I can reproduce this issue with v1.2.0 but not with v1.3.0. Maybe, some bug fixed in v1.3.0 is relating to this.