Skip to content
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

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

Open
rfyim opened this issue Sep 9, 2024 · 0 comments

Comments

@rfyim
Copy link

rfyim commented Sep 9, 2024

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.

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