Skip to content

Commit cd3acc9

Browse files
committed
Fix panic when failed to SetKeepAlive().
When SetKeepAlive fails, panic occured because mc.Close() uses unset mc.buf. Since this is before handshake, we should close socket without sending COM_QUIT.
1 parent cebeb35 commit cd3acc9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

driver.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
7272
// Enable TCP Keepalives on TCP connections
7373
if tc, ok := mc.netConn.(*net.TCPConn); ok {
7474
if err := tc.SetKeepAlive(true); err != nil {
75-
mc.Close()
75+
// Don't send COM_QUIT before handshake.
76+
mc.netConn.Close()
77+
mc.netConn = nil
7678
return nil, err
7779
}
7880
}

0 commit comments

Comments
 (0)