Skip to content

MaxOpenConns is not working #1568

@youzhixiaomutou

Description

@youzhixiaomutou

Issue description

When I operate MySQL concurrently, the number of actually created connections is greater than the set maximum number of connections. Is my usage wrong? Or is the connection leaked somewhere?

Example code

// fuzz_conn_test.go
func FuzzConn(f *testing.F) {
	db, _ := sql.Open("mysql", "dsn")
	db.SetMaxOpenConns(2)
	db.SetMaxIdleConns(2)
	db.SetConnMaxIdleTime(10 * time.Second)
	db.SetConnMaxLifetime(10 * time.Second)

	f.Fuzz(func(t *testing.T, a int) {
		go func() {
			r, _ := db.Query("select sleep(10)")
			r.Close()
		}()
	})
}

Error log

show_processlist

Configuration

Driver version (or git SHA): v1.8.0

Go version: go version go1.21.8 windows/amd64

Server version: MySQL 5.7+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions