Skip to content

Commit

Permalink
Invalidate bmqu::SharedResource<DomainManager> self explicitly
Browse files Browse the repository at this point in the history
Signed-off-by: Emelia Lei <[email protected]>
  • Loading branch information
emelialei88 committed Jan 16, 2025
1 parent 6599eca commit 0f92b2d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/groups/mqb/mqba/mqba_domainmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,17 +566,21 @@ void DomainManager::stop()
<< k_MAX_WAIT_SECONDS_AT_SHUTDOWN
<< " seconds while shutting down"
<< " bmqbrkr. rc: " << rc << ".";

// Note that 'self' variable will get invalidated when this function
// returns, which will ensure that any pending 'onDomainClosed'
// callbacks are not invoked. So there is no need to explicitly call
// 'self.invalidate()' here.
}

if (d_domainResolver_mp) {
d_domainResolver_mp->stop();
d_domainResolver_mp.clear();
}

// Notice that this invalidation is necessary.
// Without this explicit call, `self` will be invalidated
// when the function returns, which will ensure that any pending
// `onDomainClosed` callbacks are not invoked. But this is not enough
// since we want to prevent a (tiny) possibility where `latch` is
// destructed before `self` and `onDomainClosed` would be called on an
// invalid `latch`.
self.invalidate();
}

int DomainManager::locateDomain(DomainSp* domain,
Expand Down Expand Up @@ -769,8 +773,12 @@ int DomainManager::processCommand(mqbcmd::DomainsResult* result,
BALL_LOG_ERROR << "DOMAINS REMOVE fail to finish in "
<< k_MAX_WAIT_SECONDS_AT_DOMAIN_REMOVE
<< " seconds. rc: " << rc << ".";
return rc;
}

// Refer to `DomainManager::stop` to see why we need to invalidate
// `self` explicitly.
self.invalidate();
return rc; // RETURN
}
// Second pass
else {
Expand Down Expand Up @@ -807,8 +815,6 @@ int DomainManager::processCommand(mqbcmd::DomainsResult* result,
result->makeSuccess();
return 0; // RETURN
}

return 0;
}

bmqu::MemOutStream os;
Expand Down

0 comments on commit 0f92b2d

Please sign in to comment.