mysql: Strange error on killed connection

When I kill connections that have long-running queries, I get things like this:

[MySQL] 2013/12/05 22:17:19 packets.go:30: EOF
[MySQL] 2013/12/05 22:17:19 statement.go:24: Invalid Connection
[MySQL] 2013/12/05 22:17:27 packets.go:30: EOF
[MySQL] 2013/12/05 22:17:27 statement.go:24: Invalid Connection
[MySQL] 2013/12/05 22:17:39 packets.go:30: EOF
[MySQL] 2013/12/05 22:17:39 statement.go:24: Invalid Connection

I’m used to seeing this error:

2013 (HY000) at line 1: Lost connection to MySQL server during query

As far as I know, that error is actually sent across the network connection back to the client that got killed. Is this being masked in the driver or the database/sql, or is it not an error transmitted via the protocol as I think? Can we make it more clear what’s happening, somehow?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 25 (14 by maintainers)

Most upvoted comments

I think this is the problem:

package main

import (
    "database/sql"

    _ "github.com/go-sql-driver/mysql"
)

func main() {
    db, _ := sql.Open("mysql", "/")
    defer db.Close()
    tx, err := db.Begin()
    if err != nil {
        panic(err)
    }
    defer tx.Commit()
    stmt1, err := tx.Prepare("SELECT 1")
    if err != nil {
        panic(err)
    }
    rows1, err := stmt1.Query()
    if err != nil {
        panic(err)
    }
    stmt2, err := tx.Prepare("SELECT 2")
    if err != nil {
        // rows1 is not closed -> triggers busy buffer because transaction is on one connection
        // and stmt1, stmt2 use the same one.
        // Move rows1.Close() in front of tx.Prepare and it disappears
        panic(err)
    }
    rows2, err := stmt2.Query()
    if err != nil {
        panic(err)
    }
    rows1.Close()
    rows2.Close()
    stmt1.Close()
    stmt2.Close()
}

I just ran into a similar busy buffer issue and can confirm that @arnehormann seems to be correct. The issue happens when attempting to use the same transaction for multiple queries while a rows object is still open