Skip to content

Resource leakage: Error 1461: Can't create more than max_prepared_stmt_count statements (current value: 16382) #701

@ThrosturX

Description

@ThrosturX

Issue description

For some reason, this suddenly started happening. It seems like this is happening because queries built as strings are being "Prepared" behind the scenes, which is not something you want when every query is unique. The queries are executed with tx.Exec(str) and therefore there is no obvious indication to the user that statements are being prepared, causing this error to be extremely confusing.

Please note, that I'm still not entirely sure what the issue is, but this ticket represents my best guess.

Example code

// Lazy error handling, because example
func (sqlConf DBConfig) ExampleOverPrepare(items map[uint64]SomeStruct) (affected []uint64) {
    db, err := sql.Open("mysql", sqlConf.String()+"?parseTime=true")
    if err != nil { return }
    defer db.Close()
    tx, err := db.Begin()
    if err != nil { return }
    for uid, item := range items {
        queryStr := buildQuery(item) /* func(item SomeStruct) string */
        res, err := tx.Exec(queryStr)
        /* rest of block stubbed out */
    }
    if err := tx.Commit(); err != nil {
         log.Println("[ERROR]", err)
        return
    }
    return affected /* would have been set in stubbed out block */
}

Error log

Error 1461: Can't create more than max_prepared_stmt_count statements (current value: 16382)

(this is the only error message relating to DB at all, and they appear every time DB is accessed)

Configuration

Driver version (or git SHA):
0b58b37b664c21f3010e836f1b931e1d0b0b0685

Go version: run go version in your console
go version go1.9.2 linux/amd64

Server version: E.g. MySQL 5.6, MariaDB 10.0.20
MySQL 5.6.32-78.0-log

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

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