Skip to content

Write to closed Unix socket on auth failure causes "broken pipe" error #389

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
daniel-nichter opened this issue Dec 6, 2015 · 0 comments

Comments

@daniel-nichter
Copy link
Contributor

If connecting to MySQL using a socket file and authentication fails, the driver prints an error like

[MySQL] 2015/12/06 10:18:22 packets.go:118: write unix ->/var/lib/mysql.sock: write: broken pipe

to STDERR because the driver tries to send COM_QUIT on auth failure but MySQL has already closed the connection: https://dev.mysql.com/doc/internals/en/authentication-fails.html

The error is superficial [1], but I've become tired of people asking me "what does it mean?" :-) so I'm attaching a PR that fixes it by not sending COM_QUIT until successfully authenticated, else just close the network connection and do the usual internal cleanup (unset vars, etc.).

[1] Superficial to developers, but to users it raises questions because STDERR keeps us up at night.

Reproduce like:

package main

import (
    "log"
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    db, err := sql.Open("mysql", "daniel:wrong@unix(/usr/local/var/mysql/mysql.sock)/")
    if err != nil {
        log.Fatal(err)
    }
    if err := db.Ping(); err != nil {
        log.Fatal(err)
    }
}

Output:

[MySQL] 2015/12/06 12:12:40 packets.go:118: write unix ->/usr/local/var/mysql/mysql.sock: write: broken pipe
2015/12/06 12:12:40 Error 1045: Access denied for user 'daniel'@'localhost' (using password: YES)

Using latest master @ d512f20. Iirc, this issue has always existed in the diver. Not affected by Go version.

julienschmidt added a commit that referenced this issue Jan 6, 2016
…broken-pipe-error

Fixes #389 by not sending COM_QUIT until authenticated. Also refactor…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant