From 862a1a70852490cf4abfc2c73f51caa79926fcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 10 Jan 2024 19:20:12 +0100 Subject: [PATCH] Fix Admin deadlock on concurrent connections - Closes #4415 --- lib/ProxySQL_Admin.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index cc751096b4..0cb4e556d9 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -9710,9 +9710,6 @@ void ProxySQL_Admin::stats___mysql_query_rules() { } void ProxySQL_Admin::stats___proxysql_servers_checksums() { - statsdb->execute("BEGIN"); - statsdb->execute("DELETE FROM stats_proxysql_servers_checksums"); - SQLite3_result *resultset=NULL; // NOTE: This mutex unlock is required due to a race condition created when: // - One Admin session has the following callstack: // + admin_session_handler -> locks on 'sql_query_global_mutex' @@ -9727,8 +9724,10 @@ void ProxySQL_Admin::stats___proxysql_servers_checksums() { // + ProxySQL_Cluster::pull_mysql_query_rules_from_peer -> tries to lock on 'sql_query_global_mutex' // Producing a deadlock scenario between the two threads. pthread_mutex_unlock(&this->sql_query_global_mutex); - resultset=GloProxyCluster->get_stats_proxysql_servers_checksums(); + SQLite3_result* resultset = GloProxyCluster->get_stats_proxysql_servers_checksums(); pthread_mutex_lock(&this->sql_query_global_mutex); + statsdb->execute("BEGIN"); + statsdb->execute("DELETE FROM stats_proxysql_servers_checksums"); if (resultset) { int rc; sqlite3_stmt *statement1=NULL;