From 2a102e97342f24bfcebc48cda8b78b23d3511ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Sat, 28 Nov 2020 15:29:45 +0100 Subject: [PATCH 1/2] Added checks to verify that backend connection is present in several 'MySQL_Connection::async_' functions --- lib/mysql_connection.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 1fd96fe3aa..27e5e6234c 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -1616,15 +1616,9 @@ int MySQL_Connection::async_query(short event, char *stmt, unsigned long length, assert(mysql); assert(ret_mysql); server_status=parent->status; // we copy it here to avoid race condition. The caller will see this - if ( - (server_status==MYSQL_SERVER_STATUS_OFFLINE_HARD) // the server is OFFLINE as specific by the user - || - (server_status==MYSQL_SERVER_STATUS_SHUNNED && parent->shunned_automatic==true && parent->shunned_and_kill_all_connections==true) // the server is SHUNNED due to a serious issue - || - (server_status==MYSQL_SERVER_STATUS_SHUNNED_REPLICATION_LAG) // slave is lagging! see #774 - ) { + if (IsServerOffline()) return -1; - } + if (myds) { if (myds->DSS != STATE_MARIADB_QUERY) { myds->DSS = STATE_MARIADB_QUERY; @@ -1750,6 +1744,10 @@ int MySQL_Connection::async_change_user(short event) { PROXY_TRACE(); assert(mysql); assert(ret_mysql); + server_status=parent->status; // we copy it here to avoid race condition. The caller will see this + if (IsServerOffline()) + return -1; + switch (async_state_machine) { case ASYNC_CHANGE_USER_SUCCESSFUL: unknown_transaction_status = false; @@ -1793,6 +1791,10 @@ int MySQL_Connection::async_select_db(short event) { PROXY_TRACE(); assert(mysql); assert(ret_mysql); + server_status=parent->status; // we copy it here to avoid race condition. The caller will see this + if (IsServerOffline()) + return -1; + switch (async_state_machine) { case ASYNC_INITDB_SUCCESSFUL: unknown_transaction_status = false; @@ -1830,6 +1832,10 @@ int MySQL_Connection::async_set_autocommit(short event, bool ac) { PROXY_TRACE(); assert(mysql); assert(ret_mysql); + server_status=parent->status; // we copy it here to avoid race condition. The caller will see this + if (IsServerOffline()) + return -1; + switch (async_state_machine) { case ASYNC_SET_AUTOCOMMIT_SUCCESSFUL: unknown_transaction_status = false; @@ -1869,6 +1875,10 @@ int MySQL_Connection::async_set_names(short event, unsigned int c) { PROXY_TRACE(); assert(mysql); assert(ret_mysql); + server_status=parent->status; // we copy it here to avoid race condition. The caller will see this + if (IsServerOffline()) + return -1; + switch (async_state_machine) { case ASYNC_SET_NAMES_SUCCESSFUL: unknown_transaction_status = false; @@ -1908,6 +1918,10 @@ int MySQL_Connection::async_set_option(short event, bool mask) { PROXY_TRACE(); assert(mysql); assert(ret_mysql); + server_status=parent->status; // we copy it here to avoid race condition. The caller will see this + if (IsServerOffline()) + return -1; + switch (async_state_machine) { case ASYNC_SET_OPTION_SUCCESSFUL: unknown_transaction_status = false; From 86fed097daa8976bbd4479f01183f04fa7b692d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Sun, 29 Nov 2020 18:25:59 +0100 Subject: [PATCH 2/2] Fixed 'async_send_simple_command' not reporting server_status --- lib/mysql_connection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 27e5e6234c..a7446a5c09 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -2313,6 +2313,7 @@ int MySQL_Connection::async_send_simple_command(short event, char *stmt, unsigne PROXY_TRACE(); assert(mysql); assert(ret_mysql); + server_status=parent->status; // we copy it here to avoid race condition. The caller will see this if ( (parent->status==MYSQL_SERVER_STATUS_OFFLINE_HARD) // the server is OFFLINE as specific by the user ||