1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-33150 double-locking of LOCK_thd_kill in performance_schema.session_status

perfschema thread walker needs to take thread's LOCK_thd_kill to prevent
the thread from disappearing why it's being looked at.
But there's no need to lock it for the current thread.

In fact, it was harmful as some code down the stack might take
LOCK_thd_kill (e.g. set_killed() does it, and my_malloc_size_cb_func()
calls set_killed()). And it caused a bunch of mutexes being locked under
LOCK_thd_kill, which created problems later when my_malloc_size_cb_func()
called set_killed() at some unspecified point under some
random mutexes.
This commit is contained in:
Sergei Golubchik
2024-01-02 22:23:26 +01:00
parent 0a122637b5
commit c6c2a2b8d4
4 changed files with 58 additions and 9 deletions

View File

@@ -254,7 +254,8 @@ int PFS_system_variable_cache::do_materialize_all(THD *unsafe_thd)
}
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
@@ -354,7 +355,8 @@ int PFS_system_variable_cache::do_materialize_session(PFS_thread *pfs_thread)
}
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
@@ -407,7 +409,8 @@ int PFS_system_variable_cache::do_materialize_session(PFS_thread *pfs_thread, ui
}
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
@@ -458,7 +461,8 @@ int PFS_system_variable_cache::do_materialize_session(THD *unsafe_thd)
}
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
@@ -990,7 +994,8 @@ int PFS_status_variable_cache::do_materialize_all(THD* unsafe_thd)
manifest(m_safe_thd, m_show_var_array.front(), status_vars, "", false, false);
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
@@ -1036,7 +1041,8 @@ int PFS_status_variable_cache::do_materialize_session(THD* unsafe_thd)
manifest(m_safe_thd, m_show_var_array.front(), status_vars, "", false, true);
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
@@ -1078,7 +1084,8 @@ int PFS_status_variable_cache::do_materialize_session(PFS_thread *pfs_thread)
manifest(m_safe_thd, m_show_var_array.front(), status_vars, "", false, true);
/* Release lock taken in get_THD(). */
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;