Skip to content

Error: "commands out of sync. Did you run multiple statements at once?" #1673

Closed
@rks-lovelace

Description

@rks-lovelace

This error occurs in a benchmark program with driver version v1.8.1 against a 8.0.40 MySQL server. There is a similar issue in #1393, but I believe this is different.

My test program issues concurrent large LOAD DATA INFILE requests to measure sustained bulk insert rates, and it generally works well, but occasionally I get the following error:

[mysql] 2025/01/28 20:36:44 connection.go:49: busy buffer
err:[inserts commands out of sync. Did you run multiple statements at once?]

During the DB open, we issue the following:

const maxConns = 64
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(maxConns)
db.SetMaxIdleConns(maxConns)

The only call made on the returned db is the following, which is made continuously in multiple (64) goroutines. As far as I know, it should be legal to issue these calls concurrently against a single *sql.DB struct.

   sql := fmt.Sprintf("LOAD DATA LOCAL INFILE '%v' INTO TABLE movements COLUMNS TERMINATED BY ',';", filename)
   res, err := db.ExecContext(ctx, sql)
   if err != nil {
       return err
   }
   numRows, err := res.RowsAffected()
   if err != nil {
      return err
   }

My server has wait_timeout = 28800. On the last occasion, the error occurred 2600 seconds into the benchmark run (not 26,000, so only 10% of the wait_timeout). So I don't believe this should be caused by the server closing the connections from inactivity. I have 64 goroutines calling continuously on a db with 64 max connections, so I wouldn't think any are idle, anyway.

Activity

methane

methane commented on Jan 30, 2025

@methane
Member

Please try master branch and tcpdump.

DaLinR

DaLinR commented on Mar 6, 2025

@DaLinR

@methane Hello, my version is v1.7.0 and it's hard to use tcpdump in our development env.
I also noticed that if I don't set the ConnMaxLifetime and ConnMaxIdleTime configurations, there will be no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Error: "commands out of sync. Did you run multiple statements at once?" · Issue #1673 · go-sql-driver/mysql