Skip to content

Commit

Permalink
Merge pull request #1950 from Expensify/tyler-fix-deadlick
Browse files Browse the repository at this point in the history
Fix Deadlock
  • Loading branch information
tylerkaraszewski authored Nov 15, 2024
2 parents 806331e + 037d496 commit ffe0358
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ int SQLiteNode::getPriority() const {
}

void SQLiteNode::setShutdownPriority() {
SINFO("Setting priority to 1, will stop leading if required.");
SINFO("Setting priority to 1.");
unique_lock<decltype(_stateMutex)> uniqueLock(_stateMutex);
_priority = 1;

if (_state == SQLiteNodeState::LEADING) {
_changeState(SQLiteNodeState::STANDINGDOWN);
SINFO("Will stop leading.");
} else {
SData state("STATE");
state["StateChangeCount"] = to_string(_stateChangeCount);
Expand Down Expand Up @@ -591,6 +591,7 @@ bool SQLiteNode::update() {
// If no peers, we're the leader, unless we're shutting down.
if (_peerList.empty()) {
SHMMM("No peers configured, jumping to LEADING");
_priority = _originalPriority;
_changeState(SQLiteNodeState::LEADING);

// Run `update` again immediately.
Expand Down Expand Up @@ -1124,7 +1125,9 @@ bool SQLiteNode::update() {
// Check to see if we should stand down. We'll finish any outstanding commits before we actually do.
if (_state == SQLiteNodeState::LEADING) {
string standDownReason;
if (_isShuttingDown) {
if (_priority == 1) {
standDownReason = "Priority changed to 1, standing down.";
} else if (_isShuttingDown) {
// Graceful shutdown. Set priority 1 and stand down so we'll re-connect to the new leader and finish
// up our commands.
standDownReason = "Shutting down, setting priority 1 and STANDINGDOWN.";
Expand Down

0 comments on commit ffe0358

Please sign in to comment.