Fix pending trunk connection leak causing permanent peer lockout
TcpConnection::disconnect() does not emit the disconnected signal, so trunkClientDisconnected was never called to clean up m_trunk_pending_cons entries. After any connection hiccup, pending entries leaked permanently — once 2 accumulated from one IP, that peer was locked out from inbound connections forever. Clean up the pending map entry before calling disconnect() in both trunkPendingTimeout and all error paths in trunkPendingFrameReceived.
This commit is contained in:
1 parent
aa4b41f702
commit
be4d3b99c5
1 file changed
+22
-9
@@ -2150,12 +2150,23 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss.write(buf, data.size());
|
ss.write(buf, data.size());
|
||||||
|
|
||||||
|
// Helper: clean up the pending entry and disconnect.
|
||||||
|
// TcpConnection::disconnect() does NOT emit the disconnected signal,
|
||||||
|
// so trunkClientDisconnected would never fire — we must clean up the
|
||||||
|
// pending map entry ourselves before calling disconnect().
|
||||||
|
auto rejectPending = [&]()
|
||||||
|
{
|
||||||
|
delete pit->second; // timer
|
||||||
|
m_trunk_pending_cons.erase(pit);
|
||||||
|
con->disconnect();
|
||||||
|
};
|
||||||
|
|
||||||
ReflectorMsg header;
|
ReflectorMsg header;
|
||||||
if (!header.unpack(ss))
|
if (!header.unpack(ss))
|
||||||
{
|
{
|
||||||
std::cerr << "*** ERROR: TRUNK inbound: failed to unpack message header"
|
std::cerr << "*** ERROR: TRUNK inbound: failed to unpack message header"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2163,7 +2174,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
{
|
{
|
||||||
std::cerr << "*** WARNING: TRUNK inbound: expected MsgTrunkHello, got type="
|
std::cerr << "*** WARNING: TRUNK inbound: expected MsgTrunkHello, got type="
|
||||||
<< header.type() << std::endl;
|
<< header.type() << std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2172,7 +2183,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
{
|
{
|
||||||
std::cerr << "*** ERROR: TRUNK inbound: failed to unpack MsgTrunkHello"
|
std::cerr << "*** ERROR: TRUNK inbound: failed to unpack MsgTrunkHello"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2180,7 +2191,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
{
|
{
|
||||||
std::cerr << "*** ERROR: TRUNK inbound: peer sent empty trunk ID"
|
std::cerr << "*** ERROR: TRUNK inbound: peer sent empty trunk ID"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2222,7 +2233,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
<< "' section matches " << link->section()
|
<< "' section matches " << link->section()
|
||||||
<< " but authentication failed (wrong secret)"
|
<< " but authentication failed (wrong secret)"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2267,7 +2278,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
<< "' section matches " << link->section()
|
<< "' section matches " << link->section()
|
||||||
<< " but prefix mismatch: expected=[" << exp_str
|
<< " but prefix mismatch: expected=[" << exp_str
|
||||||
<< "] got=[" << peer_str << "]" << std::endl;
|
<< "] got=[" << peer_str << "]" << std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2277,7 +2288,7 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
|||||||
std::cerr << "*** ERROR: TRUNK inbound: peer '" << safe_id
|
std::cerr << "*** ERROR: TRUNK inbound: peer '" << safe_id
|
||||||
<< "' no matching section name"
|
<< "' no matching section name"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
con->disconnect();
|
rejectPending();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2315,8 +2326,10 @@ void Reflector::trunkPendingTimeout(Async::Timer* t)
|
|||||||
std::cerr << "*** WARNING: TRUNK inbound from "
|
std::cerr << "*** WARNING: TRUNK inbound from "
|
||||||
<< it->first->remoteHost()
|
<< it->first->remoteHost()
|
||||||
<< ": hello timeout — disconnecting" << std::endl;
|
<< ": hello timeout — disconnecting" << std::endl;
|
||||||
it->first->disconnect();
|
auto* con = it->first;
|
||||||
// trunkClientDisconnected will clean up
|
delete it->second; // timer
|
||||||
|
m_trunk_pending_cons.erase(it);
|
||||||
|
con->disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user