Skip to content

Crashed in bindStmtArgs(), when using the Server package to forward Execute statements from sysbench #915

Closed
@rfyim

Description

@rfyim

I have implemented a proxy for forwarding queries using the Server package. The ServerHandler is implemented as follows:

type ServerHandler struct {
	Conn  *client.Conn
}

func NewServerHandler(cfg Config) (*ServerHandler, error) {
	conn, err := client.Connect(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), cfg.User, cfg.Password, "")
	if err != nil {
		return nil, err
	}
	if err = conn.Ping(); err != nil {
		return nil, err
	}
	return &ServerHandler{
		Conn: conn,
	}, nil
}

func (h ServerHandler) UseDB(dbName string) error {
	return h.Conn.UseDB(dbName)
}

func (h ServerHandler) HandleQuery(query string) (*mysql.Result, error) {
	return h.Conn.Execute(query)
}

func (h ServerHandler) HandleFieldList(table string, fieldWildcard string) ([]*mysql.Field, error) {
	return h.Conn.FieldList(table, fieldWildcard)
}
func (h ServerHandler) HandleStmtPrepare(query string) (int, int, interface{}, error) {
	stmt, err := h.Conn.Prepare(query)
	if err != nil {
		return 0, 0, nil, err
	}
	return stmt.ParamNum(), stmt.ColumnNum(), stmt, nil
}
func (h ServerHandler) HandleStmtExecute(context interface{}, query string, args []interface{}) (*mysql.Result, error) {
	return context.(*client.Stmt).Execute(args...)
}

func (h ServerHandler) HandleStmtClose(context interface{}) error {
	return context.(*client.Stmt).Close()
}

func (h ServerHandler) HandleOtherCommand(cmd byte, data []byte) error {
	return mysql.NewError(
		mysql.ER_UNKNOWN_ERROR,
		fmt.Sprintf("command %d is not supported now", cmd),
	)
}

Unfortunately, it crashed in (c *Conn) bindStmtArgs() when I was testing with sysbench. It seems that when repeatedly executing the same statement with the same parameters, the EXECUTE message indicates that there is no need to re-bind the parameters, but the implementation of handleStmtExecute does not save the types and values of the parameters from the previous execution of the statement.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions