Commit 7c7f9bef authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix shutdown hang in dict_stats , caused by MDEV-16264

dict_stats_shutdown() can hang, waiting for timer callback to finish.
This happens because locks the same mutex, which can also used inside
timer callback, within dict_stats_schedule() function.

Fix is to make dict_stats_schedule() use mutex.try_lock() instead of
mutex.lock().

In the unlikely case of simultaneous dict_stats_schedule() setting
different timer delays, now the first one would win, which is fine.
Important is that shutdown won't hang.
parent 312569e2
...@@ -436,7 +436,16 @@ void dict_stats_start() ...@@ -436,7 +436,16 @@ void dict_stats_start()
static void dict_stats_schedule(int ms) static void dict_stats_schedule(int ms)
{ {
std::lock_guard<std::mutex> lk(dict_stats_mutex); std::unique_lock<std::mutex> lk(dict_stats_mutex, std::defer_lock);
/*
Use try_lock() to avoid deadlock in dict_stats_shutdown(), which
uses dict_stats_mutex too. If there is simultaneous timer reschedule,
the first one will win, which is fine.
*/
if (!lk.try_lock())
{
return;
}
if (dict_stats_timer) if (dict_stats_timer)
dict_stats_timer->set_time(ms,0); dict_stats_timer->set_time(ms,0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment