-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Comments
@rfyim Did you ever get this to work? I happen to be doing the same thing as you, the same way. Mine is hanging on func (h ProxyRequestHandler) HandleQuery(query string) (*mysql.Result, error) {
log.Println("In HandleQuery")
log.Println(query)
r, err := h.remoteDb.Execute(query)
if err != nil {
return nil, err
}
log.Printf("Executed query: %d", r.AffectedRows)
return r, nil
} |
For testing I'm using this: package main
import (
"fmt"
"net"
"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/server"
)
type ServerHandler struct {
Conn *client.Conn
}
type Config struct {
Host string
Port int
User string
Password string
}
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),
)
}
func main() {
l, _ := net.Listen("tcp", "127.0.0.1:4000")
c, _ := l.Accept()
cfg := Config{
Host: "127.0.0.1",
Port: 3306,
User: "root",
}
sh, _ := NewServerHandler(cfg)
conn, _ := server.NewConn(c, "root", "", sh)
for {
if err := conn.HandleCommand(); err != nil {
panic(err)
}
}
} With MySQL 9.2.0 running on port 3306. |
@dveeden I did try your handler, and I get exactly as far as my code gets, which I did make some progress on since I last wrote. I can successfully test the connection through dbeaver, and though dbeaver shows a success message, when I go to my proxy terminal, it's dead with the following output. 2025/02/06 19:45:41 new connection: 127.0.0.1:52017
2025/02/06 19:45:41 In HandleQuery
2025/02/06 19:45:41 /* mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c) */SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout
2025/02/06 19:45:41 In HandleQuery
2025/02/06 19:45:41 SET NAMES utf8mb4
2025/02/06 19:45:41 In HandleQuery
2025/02/06 19:45:41 SET character_set_results = NULL
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 SET autocommit=1
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 SET sql_mode='NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SET autocommit=1
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SELECT DATABASE()
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SHOW ENGINES
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SHOW CHARSET
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SHOW COLLATION
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SELECT @@GLOBAL.character_set_server,@@GLOBAL.collation_server
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SHOW PLUGINS
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SHOW VARIABLES LIKE 'lower_case_table_names'
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ show databases
2025/02/06 19:45:42 In HandleQuery
2025/02/06 19:45:42 /* ApplicationName=DBeaver 24.3.3 - Main */ SELECT * FROM information_schema.TABLES t
WHERE
t.TABLE_SCHEMA = 'information_schema'
AND t.TABLE_NAME = 'CHECK_CONSTRAINTS'
2025/02/06 19:45:42 Executed query: 0
2025/02/06 19:45:42 connection closed I am trying to connect to mySQL 8 RDS server |
@matttm The code I posted is just to have a full, runnable example. I did some testing with it and found a couple of issues that I'm looking into. I didn't mean to give the impression that the code I posted functions without issue. |
I tried the previously listed code with go-mysql with this PR applied: #983 Then the prepare ran ok:
And then the run indeed fails as described
With the server reporting this:
|
Note that this Python code is using prepared statements just fine. I assume that's because it is only executing the statement once. #!/bin/python3
import mysql.connector
c = mysql.connector.connect(host='127.0.0.1',port=4000,user='root',ssl_disabled=True)
cur = c.cursor(prepared=True)
cur.execute('SELECT ?', ("test",))
for row in cur:
print(row)
cur.close()
c.close() |
I have implemented a proxy for forwarding queries using the Server package. The ServerHandler is implemented as follows:
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.The text was updated successfully, but these errors were encountered: