فهرست منبع

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.
INADA Naoki 11 سال پیش
والد
کامیت
cd3acc99ca
1فایلهای تغییر یافته به همراه3 افزوده شده و 1 حذف شده
  1. 3 1
      driver.go

+ 3 - 1
driver.go

@@ -72,7 +72,9 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
 	// Enable TCP Keepalives on TCP connections
 	if tc, ok := mc.netConn.(*net.TCPConn); ok {
 		if err := tc.SetKeepAlive(true); err != nil {
-			mc.Close()
+			// Don't send COM_QUIT before handshake.
+			mc.netConn.Close()
+			mc.netConn = nil
 			return nil, err
 		}
 	}