Skip to content

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

Closed
@dveeden

Description

@dveeden

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions