Skip to content

Commit b91e77c

Browse files
committed
fix a 3-way deadlock in galera_sr.galera-features#56
rarely (try --repeat 1000), the following happens: * from wsrep_bf_abort (when a thread is being killed), wsrep-lib starts streaming_rollback that wants to convert_streaming_client_to_applier. wsrep_create_streaming_applier creates a new THD(). All while the other THD is being killed, so under LOCK_thd_kill and LOCK_thd_data. In particular, THD::init() takes LOCK_global_system_variables under LOCK_thd_kill. * updating @@wsrep_slave_threads takes LOCK_global_system_variables and LOCK_wsrep_cluster_config (in that order) and invokes wsrep_slave_threads_update() that takes LOCK_wsrep_slave_threads * wsrep_replication_process() takes LOCK_wsrep_slave_threads and invokes wsrep_close_applier(), that does thd->set_killed() which takes LOCK_thd_kill. et voilà. As a fix I copied a workaround from wsrep_cluster_address_update() to wsrep_slave_threads_update(). It seems to be safe: without mutexes a race condition is possible and a concurrent SET might change wsrep_slave_threads, but wsrep_slave_threads_update() always verifies if there's a need to do something, so it will not run twice in this case, it'll be a no-op.
1 parent 259b945 commit b91e77c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

sql/wsrep_var.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,11 @@ static void wsrep_slave_count_change_update ()
674674

675675
bool wsrep_slave_threads_update (sys_var *self, THD* thd, enum_var_type type)
676676
{
677+
mysql_mutex_unlock(&LOCK_wsrep_cluster_config);
678+
mysql_mutex_unlock(&LOCK_global_system_variables);
677679
mysql_mutex_lock(&LOCK_wsrep_slave_threads);
680+
mysql_mutex_lock(&LOCK_global_system_variables);
681+
mysql_mutex_lock(&LOCK_wsrep_cluster_config);
678682
bool res= false;
679683

680684
wsrep_slave_count_change_update();

0 commit comments

Comments
 (0)