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

Invalid connection error returned when an unrelated earlier query is cancelled #836

Closed
polyfloyd opened this issue Jul 17, 2018 · 4 comments

Comments

@polyfloyd
Copy link

Issue description

When a query is cancelled, a single subsequent unrelated query returns invalid connection instead of running normally.

Example code

package main

import (
	"context"
	"database/sql"
	"log"

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

func main() {
	db, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/some_db")
	if err != nil {
		log.Fatal(err)
	}

	for {
		ctx, cancel := context.WithCancel(context.Background())
		go cancel()

		row := db.QueryRowContext(ctx, `SELECT 1`)
		var a int
		if err := row.Scan(&a); err != nil && err != context.Canceled {
			log.Fatal(err)
		}
	}
}

Error log

[mysql] 2018/07/17 17:14:03 connection.go:372: invalid connection
...

Configuration

*Driver version (or git SHA): 749ddf1 (latest master at the time of writing)

*Go version:go version go1.10.3 darwin/amd64

*Server version: Percona 5.7

*Server OS: Debian Jessie x64

@yangjueji
Copy link

Related issue: #654
When the context is cancelled, the connection will be closed and returned back to conn pool.
Next query may get this closed connection from conn pool and show "invalid connection".
But database/sql will retry and get a non ErrBadConn connection.

@methane
Copy link
Member

methane commented Sep 20, 2018

It doesn't "return". It just "logs".

@sohag1990
Copy link

sohag1990 commented Sep 22, 2018

Here are my golang gin server Logs:

[mysql] 2018/09/22 20:12:55 packets.go:36: unexpected EOF
invalid connection
for error happend
[mysql] 2018/09/22 20:13:17 connection.go:374: invalid connection
[mysql] 2018/09/22 20:13:17 connection.go:374: invalid connection

@methane
Copy link
Member

methane commented Oct 15, 2018

fixed via #862

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

4 participants