Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash inside OverlayImpl loops over ids_ #5071

Merged
merged 8 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/test/overlay/tx_reduce_relay_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ class tx_reduce_relay_test : public beast::unit_test::suite
consumer,
std::move(stream_ptr),
overlay);
BEAST_EXPECT(
overlay.findPeerByPublicKey(key) == std::shared_ptr<PeerImp>{});
overlay.add_active(peer);
BEAST_EXPECT(overlay.findPeerByPublicKey(key) == peer);
peers.emplace_back(peer); // overlay stores week ptr to PeerImp
lid_ += 2;
rid_ += 2;
Expand Down
8 changes: 6 additions & 2 deletions src/xrpld/overlay/detail/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,9 +1163,11 @@ OverlayImpl::getActivePeers(
disabled = enabledInSkip = 0;
ret.reserve(ids_.size());

// NOTE The purpose of p is to delay the destruction of PeerImp
std::shared_ptr<PeerImp> p;
for (auto& [id, w] : ids_)
{
if (auto p = w.lock())
if (p = w.lock(); p != nullptr)
{
bool const reduceRelayEnabled = p->txReduceRelayEnabled();
// tx reduced relay feature disabled
Expand Down Expand Up @@ -1205,9 +1207,11 @@ std::shared_ptr<Peer>
OverlayImpl::findPeerByPublicKey(PublicKey const& pubKey)
{
std::lock_guard lock(mutex_);
// NOTE The purpose of peer is to delay the destruction of PeerImp
std::shared_ptr<PeerImp> peer;
for (auto const& e : ids_)
{
if (auto peer = e.second.lock())
if (peer = e.second.lock(); peer != nullptr)
{
if (peer->getNodePublic() == pubKey)
return peer;
Expand Down
Loading