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

Overlay: Do not initiate connections that will be immediately dropped #4083

Merged
merged 1 commit into from
Dec 19, 2023
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
43 changes: 26 additions & 17 deletions src/overlay/OverlayManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ constexpr uint32_t INITIAL_FLOW_CONTROL_SEND_MORE_BATCH_SIZE_BYTES{100000};
// longer than 2 seconds between re-issuing demands.
constexpr std::chrono::seconds MAX_DELAY_DEMAND{2};

bool
OverlayManagerImpl::canAcceptOutboundPeer(PeerBareAddress const& address) const
{
if (availableOutboundPendingSlots() <= 0)
{
CLOG_DEBUG(Overlay,
"Peer rejected - all outbound pending connections "
"taken: {}",
address.toString());
CLOG_DEBUG(Overlay, "If you wish to allow for more pending "
"outbound connections, please update "
"your MAX_PENDING_CONNECTIONS setting in "
"configuration file.");
return false;
}
if (mShuttingDown)
{
CLOG_DEBUG(Overlay, "Peer rejected - overlay shutting down: {}",
address.toString());
return false;
}
return true;
}

OverlayManagerImpl::PeersList::PeersList(
OverlayManagerImpl& overlayManager,
medida::MetricsRegistry& metricsRegistry,
Expand Down Expand Up @@ -365,12 +389,8 @@ OverlayManagerImpl::connectToImpl(PeerBareAddress const& address,
if (!currentConnection || (forceoutbound && currentConnection->getRole() ==
Peer::REMOTE_CALLED_US))
{
if (availableOutboundPendingSlots() <= 0)
if (!canAcceptOutboundPeer(address))
{
CLOG_DEBUG(Overlay,
"Peer rejected - all outbound pending connections "
"taken: {}",
address.toString());
return false;
}
getPeerManager().update(address, PeerManager::BackOffUpdate::INCREASE);
Expand Down Expand Up @@ -891,19 +911,8 @@ OverlayManagerImpl::addOutboundConnection(Peer::pointer peer)
releaseAssert(peer->getRole() == Peer::WE_CALLED_REMOTE);
mOutboundPeers.mConnectionsAttempted.Mark();

if (mShuttingDown || availableOutboundPendingSlots() <= 0)
if (!canAcceptOutboundPeer(peer->getAddress()))
{
if (!mShuttingDown)
{
CLOG_DEBUG(Overlay,
"Peer rejected - all outbound connections taken: {}",
peer->toString());
CLOG_DEBUG(Overlay, "If you wish to allow for more pending "
"outbound connections, please update "
"your MAX_PENDING_CONNECTIONS setting in "
"configuration file.");
}

mOutboundPeers.mConnectionsCancelled.Mark();
peer->drop("all outbound connections taken",
Peer::DropDirection::WE_DROPPED_REMOTE,
Expand Down
4 changes: 4 additions & 0 deletions src/overlay/OverlayManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,9 @@ class OverlayManagerImpl : public OverlayManager
std::vector<Peer::pointer>& result);
void shufflePeerList(std::vector<Peer::pointer>& peerList);
AdjustedFlowControlConfig getFlowControlBytesConfig() const override;

// Returns `true` iff the overlay can accept the outbound peer at `address`.
// Logs whenever a peer cannot be accepted.
bool canAcceptOutboundPeer(PeerBareAddress const& address) const;
};
}