diff --git a/go/mysql/conn.go b/go/mysql/conn.go index 439ff282608..dcd023738ec 100644 --- a/go/mysql/conn.go +++ b/go/mysql/conn.go @@ -1347,7 +1347,11 @@ func (c *Conn) handleNextCommand(handler Handler) error { // Clean up and reset the connection c.recycleReadPacket() c.discardCursor() - handler.ComResetConnection(c) + err = handler.ComResetConnection(c) + if err != nil { + log.Errorf("Error resetting connection (ID %d): %v", c.ConnectionID, err) + c.writeErrorPacketFromError(err) + } // Reset prepared statements c.PrepareData = make(map[uint32]*PrepareData) err = c.writeOKPacket(0, 0, 0, 0) diff --git a/go/mysql/server.go b/go/mysql/server.go index f6b069595a9..2a0911d6e4a 100644 --- a/go/mysql/server.go +++ b/go/mysql/server.go @@ -122,7 +122,11 @@ type Handler interface { WarningCount(c *Conn) uint16 // ComResetConnection is called when a connection receives a COM_RESET_CONNECTION signal. - ComResetConnection(c *Conn) + // This is used to reset the session state (e.g. clearing user vars, resetting session vars, releasing + // locks, releasing cached prepared statements, etc). One of the primary use cases for COM_RESET_CONNECTION + // is to reset a pooled connection's session state so that it can be safely returned to the connection pool + // and given to another application process to reuse. + ComResetConnection(c *Conn) error // ParserOptionsForConnection returns any parser options that should be used for the given connection. For // example, if the connection has enabled ANSI_QUOTES or ANSI SQL_MODE, then the parser needs to know that diff --git a/go/mysql/server_test.go b/go/mysql/server_test.go index cd93fa438d2..ece343faac0 100644 --- a/go/mysql/server_test.go +++ b/go/mysql/server_test.go @@ -305,8 +305,8 @@ func (th *testHandler) ComStmtExecute(c *Conn, prepare *PrepareData, callback fu } } -func (th *testHandler) ComResetConnection(c *Conn) { - +func (th *testHandler) ComResetConnection(c *Conn) error { + return nil } func (th *testHandler) WarningCount(c *Conn) uint16 {