Fix trunk reconnect storm with per-IP pending connection limit
When two trunk peers simultaneously reconnect, rapid retries from one peer could fill the global pending connection pool (5 slots), starving other peers and creating a reject→reconnect→reject loop. Add a per-IP limit of 2 pending (pre-hello) connections in the trunk server, so one misbehaving or rapidly-reconnecting peer cannot exhaust the pool. Also increase outbound reconnect backoff (2s min, 30s max) to reduce retry pressure after connection failures.
This commit is contained in:
1 parent
4e6bff7962
commit
7d1aeff623
2 files changed
+26
-3
No files matched your search
@@ -2045,11 +2045,32 @@ void Reflector::initTrunkServer(void)
|
||||
|
||||
void Reflector::trunkClientConnected(Async::FramedTcpConnection* con)
|
||||
{
|
||||
// Reject connections beyond the pending limit to prevent fd exhaustion
|
||||
// Per-IP pending limit: allow at most 2 pending (pre-hello) connections per
|
||||
// source IP to prevent reconnect storms where rapid retries from one peer
|
||||
// fill the global pending pool and starve other peers. A limit of 2 (rather
|
||||
// than 1) tolerates one overlapping connection during normal reconnects.
|
||||
const Async::IpAddress remote_ip = con->remoteHost();
|
||||
unsigned ip_pending = 0;
|
||||
for (const auto& kv : m_trunk_pending_cons)
|
||||
{
|
||||
if (kv.first->remoteHost() == remote_ip)
|
||||
{
|
||||
++ip_pending;
|
||||
}
|
||||
}
|
||||
if (ip_pending >= 2)
|
||||
{
|
||||
std::cerr << "*** WARNING: TRUNK inbound from " << remote_ip
|
||||
<< ": too many pending connections from this IP — rejecting"
|
||||
<< std::endl;
|
||||
con->disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reject connections beyond the global pending limit to prevent fd exhaustion
|
||||
if (m_trunk_pending_cons.size() >= TRUNK_MAX_PENDING_CONS)
|
||||
{
|
||||
std::cerr << "*** WARNING: TRUNK inbound from "
|
||||
<< con->remoteHost()
|
||||
std::cerr << "*** WARNING: TRUNK inbound from " << remote_ip
|
||||
<< ": too many pending connections — rejecting" << std::endl;
|
||||
con->disconnect();
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user