Skip to content

Commit

Permalink
always release data_lock mutex to avoid deadlock
Browse files Browse the repository at this point in the history
Summary: in stage-1 replicaset, when kill a secondary instance, sometime the instance will run into deadlock due to process_raft_queue thread forgot to release its acquired mutex in raft_change_master

Reviewed By: Pushapgl, bhatvinay

Differential Revision: D27602667
  • Loading branch information
luqun authored and inikep committed May 17, 2023
1 parent ed270bc commit 92f572c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sql/rpl_replica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,10 @@ int raft_change_master(
channel_map.rdlock();
Master_info *mi = channel_map.get_default_channel_mi();

if (!mi) goto end;
if (!mi) {
channel_map.unlock();
DBUG_RETURN(error);
}

mysql_mutex_lock(&mi->data_lock);
strmake(mi->host, const_cast<char *>(master_instance.first.c_str()),
Expand Down Expand Up @@ -1826,12 +1829,12 @@ int raft_change_master(
}
mi->inited = true;
mi->flush_info(true);
mysql_mutex_unlock(&mi->rli->data_lock);
mysql_mutex_unlock(&mi->data_lock);

// changing to a slave. set the is_slave flag
is_slave = true;
end:
mysql_mutex_unlock(&mi->rli->data_lock);
mysql_mutex_unlock(&mi->data_lock);
channel_map.unlock();
DBUG_RETURN(error);
}
Expand Down

0 comments on commit 92f572c

Please sign in to comment.