Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thrsafe api report "unlock of unlocked mutex" when executeing multi statements #32

Closed
littlewhitetwo opened this issue Aug 8, 2012 · 1 comment

Comments

@littlewhitetwo
Copy link

hi I am using the thrsafe api to execute multiple statements, and it panic and report "unlock of unlocked mutex" .
the SQL is "set @rtn= 0; CALL sp_test(1, @rtn); select @rtn as aaa;"
i intented to call a stored procedure and get the result .

Here is how i reproduced this issue

package main

import (
    "fmt"
    "github.com/ziutek/mymysql/mysql"
    "os"
)

import "github.com/ziutek/mymysql/thrsafe"

//import "github.com/ziutek/mymysql/native"

func printOK() {
    fmt.Println("OK")
}

func checkError(err error) {
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

func checkedResult(rows []mysql.Row, res mysql.Result, err error) ([]mysql.Row,
    mysql.Result) {
    checkError(err)
    return rows, res
}

func main() {
    user := "root"
    pass := "mysql"
    dbname := "test"
    addr := "127.0.0.1:3306"

    //  db := native.New("tcp", "", addr, user, pass, dbname)
    db := thrsafe.New("tcp", "", addr, user, pass, dbname)

    fmt.Printf("Connect to %s... ", addr)
    checkError(db.Connect())
    printOK()

    //  res, err := db.Start("set @rtn= 0; CALL sp_test(1, @rtn); select @rtn as aaa;")     //it panic!
    res, err := db.Start("set @rtn= 0; select @rtn as aaa;")                 // it panic!
    //  res, err := db.Start("select * from user; select count(*) from user;")    //it works!

    if err == nil {
        printOK()
    } else if e, ok := err.(*mysql.Error); ok {
        fmt.Println(e)
        return
    } else {
        checkError(err)
    }
    index := 0
    for {
        index++

        fmt.Printf("loop :%d res :%+v more:%+v only:%+v\n", index, res.Fields(), res.MoreResults(), res.StatusOnly())

        if !res.StatusOnly() {

            row, err := res.GetRows()
            if err != nil {

                fmt.Printf("GetRow error :%s \n", err)
            }
            if row == nil {

                fmt.Printf("why nil\n")
                break
            }
            fmt.Printf("row :%+v  \n", row)
        }
        if res.MoreResults() {
            res, err = res.NextResult()
            if err != nil {
                fmt.Printf("Get NextResult error err:%s\n", err)
                break
            }
            if res == nil {
                panic("3Hmm, there is no result. Why?!")
            }
        } else {
            fmt.Printf("good! no result, break\n")
            break
        }

    }
    fmt.Print("Close connection... ")
    checkError(db.Close())
    printOK()
}

when i run this code , it produce this msg

panic: sync: unlock of unlocked mutex

goroutine 1 [running]:
sync.(*Mutex).Unlock(0xf840057060, 0x36a1b3d8)
    /usr/local/go/src/pkg/sync/mutex.go:76 +0x7f
github.com/ziutek/mymysql/thrsafe.(*Conn).unlock(0xf840042740, 0xf840046100)
    /usr/local/go/src/pkg/github.com/ziutek/mymysql/thrsafe/thrsafe.go:36 +0x4f
github.com/ziutek/mymysql/thrsafe.(*Result).ScanRow(0xf840043820, 0xf8400466e0, 0x100000001, 0x7fb39b3bfca0, 0x10, ...)
    /usr/local/go/src/pkg/github.com/ziutek/mymysql/thrsafe/thrsafe.go:136 +0x160
github.com/ziutek/mymysql/mysql.GetRow(0xf84008e120, 0xf840043820, 0xf840043820, 0xf84008e120, 0xf840043820, ...)
    /usr/local/go/src/pkg/github.com/ziutek/mymysql/mysql/utils.go:33 +0x6d
github.com/ziutek/mymysql/thrsafe.(*Result).GetRow(0xf840043820, 0x0, 0x0, 0x1)
    /usr/local/go/src/pkg/github.com/ziutek/mymysql/thrsafe/thrsafe.go:142 +0x49
github.com/ziutek/mymysql/mysql.GetRows(0xf84008e120, 0xf840043820, 0xf8400466d0, 0x100000001, 0x0, ...)
    /usr/local/go/src/pkg/github.com/ziutek/mymysql/mysql/utils.go:64 +0x74
github.com/ziutek/mymysql/thrsafe.(*Result).GetRows(0xf840043820, 0x706f6f6c00000000, 0x7fb39b3bfea0, 0x400000004)
    /usr/local/go/src/pkg/github.com/ziutek/mymysql/thrsafe/thrsafe.go:220 +0x49
main.main()
    /home/white/Code/go/mysql/mysql.go:63 +0x508
....

when I changed the api to native api, it could get the correct result , But thrsafe api failed!

@ziutek
Copy link
Owner

ziutek commented Aug 10, 2012

It looks like a real issue, but I am very busy for the next two weeks (can't handle any issues on github).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants