Skip to content

bugfix: fix i/o timeout: connection was bad #605

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

Merged
merged 2 commits into from
Jul 27, 2021

Conversation

theharveyz
Copy link
Contributor

No description provided.

@lance6716
Copy link
Collaborator

Hi, could you explain what's the scenario and problem you want to fix?

@theharveyz
Copy link
Contributor Author

theharveyz commented Jul 27, 2021

Hi, could you explain what's the scenario and problem you want to fix?

ping 这里会导致 Conn 的读写期限被设置成很短的值,后面被业务逻辑获取后,会频繁出现 "connection was bad" 的问题。
复现代码:

--

setting a very short deadline for Conn in ping will cause "connection was bad" when it is later used.

reproduce code:

package main

import (
	"context"
	"log"

	"github.com/gin-gonic/gin"
	"github.com/go-mysql-org/go-mysql/client"
	"github.com/sirupsen/logrus"
)

var pool *client.Pool
var l *logrus.Logger

func main() {
	router := gin.New()
	l = logrus.New()
	pool = client.NewPool(l.Debugf, 10, 10, 5, "127.0.0.1:3306", `{user}`, `{pwd}`, `{dbname}`)
	router.GET("/test", Test)
	router.Run("127.0.0.1:8000")
}

func Test(gin *gin.Context) {
	conn, _ := pool.GetConn(context.Background())
	defer pool.PutConn(conn)
	
	res, err := conn.Execute("SELECT * FROM test WHERE id > ?", 0)
	if err != nil {
		log.Printf(" Execute Err : %s\n", err)
	}

	if err != nil {
		gin.SecureJSON(200, err.Error())
	} else {
		gin.SecureJSON(200, err)
	}
}

@lance6716 lance6716 requested a review from atercattus July 27, 2021 07:42
@atercattus atercattus merged commit 5ee187d into go-mysql-org:master Jul 27, 2021
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

Successfully merging this pull request may close these issues.

3 participants