Skip to content

Irrelevant error when connection fails: busy buffer, commands out of sync #1669

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

Closed
tdewolff opened this issue Jan 27, 2025 · 3 comments
Closed

Comments

@tdewolff
Copy link

I had a whole post written to explain my problem, but while writing I found the solution. The error however is very vague and led me to about 6h lost digging for a bug.

In my case the MySQL server was listening on a socket and not on localhost:3306, however connecting to the latter like below was giving an error only when executing a query, not when connecting. Nor was the error appropriate for the problem.

Example:

	db, err := sql.Open("mysql", "USER:PASSWORD@tcp(localhost:3306)/DBNAME?charset=utf8")
	if err != nil {
		log.Fatalln(err)
	}
	rows, err := db.Query("SELECT domain FROM domains")
	if err != nil {
		log.Fatalln(err) // error here
	}
	// ...

This fails with:

[mysql] 2025/01/27 21:44:02 connection.go:49: busy buffer
commands out of sync. Did you run multiple statements at once?

Using unix(/var/lib/mysql/mysql.sock) as the host fixes the problem. I'm running MariaDB 10.3.28

@methane
Copy link
Member

methane commented Jan 28, 2025

It is database/sql design. sql.Open() creates connection pool, not a connection.
If you want to check connection, call db.Ping().

@methane methane closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2025
@tdewolff
Copy link
Author

Then why doesn't the error from Query say so? Why does it say busy buffer, commands out of sync, when it should say connection failed? That's not by design I may hope...

@methane
Copy link
Member

methane commented Jan 28, 2025

I don't know. Ask to your localhost:3306.

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

No branches or pull requests

2 participants