diff --git a/include/gen_utils.h b/include/gen_utils.h index 0503669ab..ea9b8fbcb 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -229,6 +229,23 @@ inline unsigned long long realtime_time() { clock_gettime(CLOCK_REALTIME, &ts); return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } + +/** + * @brief ProxySQL replacement function for 'mysql_stmt_close'. Closes a + * MYSQL_STMT avoiding any blocking commands that are sent by default + * 'mysql_stmt_close'. + * + * NOTE: This function is not safe, caller must check that the supplied + * argument is not NULL. + * + * @param mysql_stmt An already initialized 'MYSQL_STMT'. Caller must ensure + * that the supplied argument is not NULL. + * + * @return The result of calling 'mysql_stmt_close' function over the internally + * modified 'MYSQL_STMT'. + */ +my_bool proxy_mysql_stmt_close(MYSQL_STMT* mysql_stmt); + #endif /* __GEN_FUNCTIONS */ bool Proxy_file_exists(const char *); diff --git a/lib/MySQL_PreparedStatement.cpp b/lib/MySQL_PreparedStatement.cpp index c8616e457..3007461a4 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -691,12 +691,7 @@ MySQL_STMTs_local_v14::~MySQL_STMTs_local_v14() { it != global_stmt_to_backend_stmt.end(); ++it) { uint64_t global_stmt_id = it->first; MYSQL_STMT *stmt = it->second; - if (stmt->mysql) { - stmt->mysql->stmts = - list_delete(stmt->mysql->stmts, &stmt->list); - } - stmt->mysql = NULL; - mysql_stmt_close(stmt); + proxy_mysql_stmt_close(stmt); GloMyStmt->ref_count_server(global_stmt_id, -1); } } diff --git a/lib/gen_utils.cpp b/lib/gen_utils.cpp index 108211df9..f24ed64f3 100644 --- a/lib/gen_utils.cpp +++ b/lib/gen_utils.cpp @@ -219,3 +219,15 @@ bool Proxy_file_regular(const char *path) { if (sb.st_mode & S_IFREG) return true; return false; } + +my_bool proxy_mysql_stmt_close(MYSQL_STMT* stmt) { + // Clean internal structures for 'stmt->mysql->stmts'. + if (stmt->mysql) { + stmt->mysql->stmts = + list_delete(stmt->mysql->stmts, &stmt->list); + } + // Nullify 'mysql' field to avoid sending a blocking command to the server. + stmt->mysql = NULL; + // Perform the regular close operation. + return mysql_stmt_close(stmt); +} diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 3a5b12659..0b54334ec 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -2151,7 +2151,7 @@ void MySQL_Connection::async_free_result() { // initialized, it must be freed. For more context see #3525. if (this->async_state_machine == ASYNC_STMT_PREPARE_FAILED) { if (query.stmt != NULL) { - mysql_stmt_close(query.stmt); + proxy_mysql_stmt_close(query.stmt); } } query.stmt=NULL;