mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Issues with GET_LOCK and a too long lock name on MySQL 5.7

Open dveeden opened this issue 10 years ago • 3 comments

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

dveeden avatar Nov 13 '15 13:11 dveeden

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

dveeden avatar Nov 13 '15 13:11 dveeden

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?

dveeden avatar Nov 13 '15 14:11 dveeden

Any update on this? Maybe an idea about how this should be fixed?

dveeden avatar Mar 16 '16 21:03 dveeden

I feel that this should be closed since MySQL 5.7 has reached its end of life.

ravarage avatar Feb 18 '24 06:02 ravarage

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.

methane avatar Feb 19 '24 14:02 methane