Skip to content

Commit

Permalink
Merge pull request #4052 from sysown/v2.x-fix_autocommit_handshake_resp
Browse files Browse the repository at this point in the history
Fix autocommit invalidly reported in several cases
  • Loading branch information
renecannao authored Jan 10, 2023
2 parents 51f4494 + 0e7afa3 commit 709149f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5399,7 +5399,7 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
(strcmp(client_addr,(char *)"::1")==0)
) {
// we are good!
client_myds->myprot.generate_pkt_OK(true,NULL,NULL, _pid, 0,0,0,0,NULL);
client_myds->myprot.generate_pkt_OK(true, NULL, NULL, _pid, 0, 0, 2, 0, NULL);
handshake_err = false;
GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_AUTH_OK, this, NULL);
status=WAITING_CLIENT_DATA;
Expand Down Expand Up @@ -5445,7 +5445,7 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
//client_myds->myprot.generate_pkt_OK(true,NULL,NULL, (is_encrypted ? 3 : 2), 0,0,0,0,NULL,false);
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION,8,"Session=%p , DS=%p . STATE_CLIENT_AUTH_OK\n", this, client_myds);
GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_AUTH_OK, this, NULL);
client_myds->myprot.generate_pkt_OK(true,NULL,NULL, _pid, 0,0,0,0,NULL);
client_myds->myprot.generate_pkt_OK(true, NULL, NULL, _pid, 0, 0, 2, 0, NULL);
handshake_err = false;
status=WAITING_CLIENT_DATA;
client_myds->DSS=STATE_CLIENT_AUTH_OK;
Expand Down Expand Up @@ -6712,7 +6712,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
client_authenticated=false;
if (client_myds->myprot.process_pkt_COM_CHANGE_USER((unsigned char *)pkt->ptr, pkt->size)==true) {
l_free(pkt->size,pkt->ptr);
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,0,0,NULL);
client_myds->myprot.generate_pkt_OK(true, NULL, NULL, 1, 0, 0, 2, 0, NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
*wrong_pass=false;
Expand Down Expand Up @@ -6802,7 +6802,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C

l_free(pkt->size,pkt->ptr);
client_myds->setDSS_STATE_QUERY_SENT_NET();
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,0,0,NULL);
client_myds->myprot.generate_pkt_OK(true, NULL, NULL, 1, 0, 0, 2, 0, NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
} else {
Expand Down
53 changes: 47 additions & 6 deletions test/tap/tests/test_server_sess_status-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(int argc, char** argv) {
CommandLine cl;

// TODO: Harcoded for now, this is an initial version of the test.
plan(4);
plan(6);

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
Expand Down Expand Up @@ -133,18 +133,59 @@ int main(int argc, char** argv) {
exp_mysql_srv_st, mysql->server_status
);

// TODO-FIXME: We are setting here '0' as expecting to see 'SERVER_STATUS_AUTOCOMMIT' to be false.
// This is a bug that should be addressed, and this test revisited.
uint32_t exp_proxy_srv_st = SERVER_STATUS_AUTOCOMMIT;

ok(
proxy->server_status == 0,
exp_proxy_srv_st == proxy->server_status,
"ProxySQL init server status should match expected - exp: '%d', act:'%d'",
0, proxy->server_status
exp_proxy_srv_st, proxy->server_status
);

int err_code = mysql_reset_connection(proxy);
if (err_code != EXIT_SUCCESS) {
diag(
"'mysql_reset_connection' failed with error: (%d,'%s') at ('%s':'%d')",
mysql_errno(proxy), mysql_error(proxy), __FILE__, __LINE__
);
return EXIT_FAILURE;
}

ok(
exp_proxy_srv_st == proxy->server_status,
"ProxySQL server status after reset connection should match expected - exp: '%d', act:'%d'",
exp_proxy_srv_st, proxy->server_status
);

const string username = { "sbtest_reset_conn_1" };
const string password = { "sbtest_reset_conn_1" };
const string attributes = { "" };
err_code = create_proxysql_user(admin, username, password, attributes);
if (err_code) {
diag("'create_proxysql_user' failed at ('%s':'%d') with error '%d'", __FILE__, __LINE__, err_code);
return EXIT_FAILURE;
}

MYSQL_QUERY(admin, "LOAD MYSQL USERS TO RUNTIME");

err_code = mysql_change_user(proxy, username.c_str(), password.c_str(), NULL);
if (err_code != EXIT_SUCCESS) {
diag(
"'mysql_change_user' failed with error: (%d,'%s') at ('%s':'%d')",
mysql_errno(proxy), mysql_error(proxy), __FILE__, __LINE__
);
return EXIT_FAILURE;
}

ok(
exp_proxy_srv_st == proxy->server_status,
"ProxySQL server status after change user should match expected - exp: '%d', act:'%d'",
exp_proxy_srv_st, proxy->server_status
);

mysql_query(proxy, "SET SESSION session_track_transaction_info=\"CHARACTERISTICS\"");
mysql_query(proxy, "START TRANSACTION");

uint32_t exp_proxy_srv_st = SERVER_STATUS_AUTOCOMMIT | SERVER_STATUS_IN_TRANS;
exp_proxy_srv_st = SERVER_STATUS_AUTOCOMMIT | SERVER_STATUS_IN_TRANS;

ok(
exp_proxy_srv_st == proxy->server_status,
Expand Down

0 comments on commit 709149f

Please sign in to comment.