Skip to content

bad connection #1096

Closed
Closed
@LeeDF

Description

@LeeDF

Issue description

bad connection
$ wrk -c300 -d10m -t8 url
SetMaxOpenConns(100)
When wrk just started, Occasional bad connection error, And the number of mysql PROCESSLIST is less than 100, around 70
I modified the file

database/sql/sql.go 

func OpenDB(c driver.Connector) *DB {
	ctx, cancel := context.WithCancel(context.Background())
	db := &DB{
		connector:    c,
		openerCh:     make(chan struct{}, connectionRequestQueueSize),
		resetterCh:   make(chan *driverConn, 50),
		lastPut:      make(map[*driverConn]string),
		connRequests: make(map[uint64]chan connRequest),
		stop:         cancel,
	}

	go db.connectionOpener(ctx)
	go db.connectionResetter(ctx)

	return db
}

Changed the buffer length of resetterCh

resetterCh:   make(chan *driverConn, 100),

Solved the bad connection problem, and the number of mysql PROCESSLIST instantly reached 100

Example code

If possible, please enter some example code here to reproduce the issue.

Error log

bad connection

Configuration

Driver version (or git SHA):

Go version: run go version in your console
1.14
Server version: E.g. MySQL 5.6, MariaDB 10.0.20

Server OS: E.g. Debian 8.1 (Jessie), Windows 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions