Skip to content

returning rows and signaling error results in locked state #422

Closed
@0xor1

Description

@0xor1

mysql version: 5.7.10
mysql driver commit: 267b128
go version: 1.5.1 + 1.5.3
os: windows 8.1

package main

import(
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
    "fmt"
)

const(
    sqlDriver = "mysql"
    sqlConnectionString = "usr:pwd@tcp(localhost:3306)/my_test_db?parseTime=true&loc=UTC"
)

//This was run with go version 1.5.3, mysql 5.7.10 and go-sql-driver/mysql commit 267b128680c46286b9ca13475c3cca5de8f79bd7

func main(){
    db, _ := sql.Open(sqlDriver, sqlConnectionString)
    db.Exec(`
        CREATE PROCEDURE test_proc()
        BEGIN
            SELECT TRUE;
            SIGNAL SQLSTATE
                '45001'
            SET
                MESSAGE_TEXT = "an error",
                MYSQL_ERRNO = 45001;
        END
    `)
    val := false

    rows, err = db.Query("CALL test_proc()")
    if err == nil {
        fmt.Println("unexpected err is nil")
    }

    if rows == nil {
        fmt.Println("unexpected rows is nil")
    }

    for rows.Next() {
        if err = rows.Scan(&val); err != nil {
            fmt.Println("unexpected err is not nil")
        }
        if val != true {
            fmt.Println("unexpected val is not true")
        }
        fmt.Println("program will lock up on next entry to rows.Next()")
    }
    rows.Close()

    fmt.Scanln()
}

This produces output:

unexpected err is nil
program will lock up on next entry to rows.Next()

before getting stuck in the locked state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions