mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix crash in Slot::deletePeer (#5635)
Fix crash due to recurrent call to `Slot::deletePeer` (via `OverlayImpl::unsquelch`) when a peer is disconnected at just the wrong moment.
This commit is contained in:
@@ -446,6 +446,8 @@ Slot<clock_type>::deletePeer(PublicKey const& validator, id_t id, bool erase)
|
||||
auto it = peers_.find(id);
|
||||
if (it != peers_.end())
|
||||
{
|
||||
std::vector<Peer::id_t> toUnsquelch;
|
||||
|
||||
JLOG(journal_.trace())
|
||||
<< "deletePeer: " << Slice(validator) << " " << id << " selected "
|
||||
<< (it->second.state == PeerState::Selected) << " considered "
|
||||
@@ -457,7 +459,7 @@ Slot<clock_type>::deletePeer(PublicKey const& validator, id_t id, bool erase)
|
||||
for (auto& [k, v] : peers_)
|
||||
{
|
||||
if (v.state == PeerState::Squelched)
|
||||
handler_.unsquelch(validator, k);
|
||||
toUnsquelch.push_back(k);
|
||||
v.state = PeerState::Counting;
|
||||
v.count = 0;
|
||||
v.expire = now;
|
||||
@@ -479,6 +481,10 @@ Slot<clock_type>::deletePeer(PublicKey const& validator, id_t id, bool erase)
|
||||
|
||||
if (erase)
|
||||
peers_.erase(it);
|
||||
|
||||
// Must be after peers_.erase(it)
|
||||
for (auto const& k : toUnsquelch)
|
||||
handler_.unsquelch(validator, k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1423,7 +1423,12 @@ OverlayImpl::updateSlotAndSquelch(
|
||||
if (!strand_.running_in_this_thread())
|
||||
return post(
|
||||
strand_,
|
||||
[this, key, validator, peers = std::move(peers), type]() mutable {
|
||||
// Must capture copies of reference parameters (i.e. key, validator)
|
||||
[this,
|
||||
key = key,
|
||||
validator = validator,
|
||||
peers = std::move(peers),
|
||||
type]() mutable {
|
||||
updateSlotAndSquelch(key, validator, std::move(peers), type);
|
||||
});
|
||||
|
||||
@@ -1444,9 +1449,12 @@ OverlayImpl::updateSlotAndSquelch(
|
||||
return;
|
||||
|
||||
if (!strand_.running_in_this_thread())
|
||||
return post(strand_, [this, key, validator, peer, type]() {
|
||||
updateSlotAndSquelch(key, validator, peer, type);
|
||||
});
|
||||
return post(
|
||||
strand_,
|
||||
// Must capture copies of reference parameters (i.e. key, validator)
|
||||
[this, key = key, validator = validator, peer, type]() {
|
||||
updateSlotAndSquelch(key, validator, peer, type);
|
||||
});
|
||||
|
||||
slots_.updateSlotAndSquelch(key, validator, peer, type, [&]() {
|
||||
reportInboundTraffic(TrafficCount::squelch_ignored, 0);
|
||||
|
||||
Reference in New Issue
Block a user