Add TRUNK_DEBUG option for verbose trunk connection diagnostics
Add TRUNK_DEBUG=1 config option in [GLOBAL] that enables detailed logging of trunk connection lifecycle: state on connect/disconnect, heartbeat countdown warnings near timeout, every non-heartbeat frame with direction and type, send path decisions, and prefix matching details on the trunk server. Helps diagnose connection issues reported in #1 where the remote side kills connections.
This commit is contained in:
1 parent
9c359ba507
commit
638d3c527e
8 files changed
+186
-2
No files matched your search
@@ -455,6 +455,18 @@ bool Reflector::initialize(Async::Config &cfg)
|
||||
return true;
|
||||
}
|
||||
|
||||
// TRUNK_DEBUG — verbose logging for diagnosing trunk connection issues
|
||||
std::string trunk_debug_str;
|
||||
if (cfg.getValue("GLOBAL", "TRUNK_DEBUG", trunk_debug_str))
|
||||
{
|
||||
m_trunk_debug = (trunk_debug_str == "1" || trunk_debug_str == "true"
|
||||
|| trunk_debug_str == "yes");
|
||||
if (m_trunk_debug)
|
||||
{
|
||||
std::cout << "Trunk debug logging enabled" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
initTrunkLinks();
|
||||
initTrunkServer();
|
||||
initSatelliteServer();
|
||||
@@ -2079,6 +2091,13 @@ void Reflector::trunkClientConnected(Async::FramedTcpConnection* con)
|
||||
std::cout << "TRUNK: Inbound connection from "
|
||||
<< con->remoteHost() << ":" << con->remotePort() << std::endl;
|
||||
|
||||
if (m_trunk_debug)
|
||||
{
|
||||
std::cout << "TRUNK [DEBUG]: pending_count=" << m_trunk_pending_cons.size()
|
||||
<< " ip_pending=" << ip_pending
|
||||
<< " from " << remote_ip << std::endl;
|
||||
}
|
||||
|
||||
// Set up a timeout for receiving the hello message
|
||||
auto* timer = new Async::Timer(10000, Async::Timer::TYPE_ONESHOT);
|
||||
timer->expired.connect(
|
||||
@@ -2187,6 +2206,12 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
||||
{
|
||||
if (!msg.verify(link->secret()))
|
||||
{
|
||||
if (m_trunk_debug)
|
||||
{
|
||||
std::cout << "TRUNK [DEBUG]: peer '" << safe_id
|
||||
<< "' HMAC mismatch against " << link->section()
|
||||
<< std::endl;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2214,6 +2239,24 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
||||
matched_link = link;
|
||||
break;
|
||||
}
|
||||
else if (m_trunk_debug)
|
||||
{
|
||||
std::string exp_str, peer_str;
|
||||
for (const auto& p : sorted_expected)
|
||||
{
|
||||
if (!exp_str.empty()) exp_str += ",";
|
||||
exp_str += p;
|
||||
}
|
||||
for (const auto& p : sorted_peer)
|
||||
{
|
||||
if (!peer_str.empty()) peer_str += ",";
|
||||
peer_str += p;
|
||||
}
|
||||
std::cout << "TRUNK [DEBUG]: peer '" << safe_id
|
||||
<< "' secret OK for " << link->section()
|
||||
<< " but prefix mismatch: expected=[" << exp_str
|
||||
<< "] got=[" << peer_str << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (matched_link == nullptr)
|
||||
@@ -2225,6 +2268,12 @@ void Reflector::trunkPendingFrameReceived(Async::FramedTcpConnection* con,
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_trunk_debug)
|
||||
{
|
||||
std::cout << "TRUNK [DEBUG]: peer '" << safe_id
|
||||
<< "' matched to " << matched_link->section() << std::endl;
|
||||
}
|
||||
|
||||
// Clean up the pending entry
|
||||
delete pit->second; // timer
|
||||
m_trunk_pending_cons.erase(pit);
|
||||
|
||||
@@ -299,6 +299,7 @@ class Reflector : public sigc::trackable
|
||||
|
||||
std::vector<TrunkLink*> m_trunk_links;
|
||||
std::set<uint32_t> m_cluster_tgs;
|
||||
bool m_trunk_debug = false;
|
||||
static const size_t TRUNK_MAX_PENDING_CONS = 5;
|
||||
|
||||
FramedTcpServer* m_trunk_srv = nullptr;
|
||||
|
||||
@@ -184,9 +184,17 @@ bool TrunkLink::initialize(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
// TRUNK_DEBUG — verbose logging for connection diagnostics
|
||||
std::string debug_str;
|
||||
if (m_cfg.getValue("GLOBAL", "TRUNK_DEBUG", debug_str))
|
||||
{
|
||||
m_debug = (debug_str == "1" || debug_str == "true" || debug_str == "yes");
|
||||
}
|
||||
|
||||
cout << m_section << ": Trunk to " << m_peer_host << ":" << m_peer_port
|
||||
<< " local_prefix=" << joinPrefixes(m_local_prefix)
|
||||
<< " remote_prefix=" << joinPrefixes(m_remote_prefix) << endl;
|
||||
<< " remote_prefix=" << joinPrefixes(m_remote_prefix)
|
||||
<< (m_debug ? " [debug on]" : "") << endl;
|
||||
|
||||
m_con.addStaticSRVRecord(0, 0, 0, m_peer_port, m_peer_host);
|
||||
m_con.setReconnectMinTime(2000);
|
||||
@@ -315,6 +323,16 @@ void TrunkLink::acceptInboundConnection(Async::FramedTcpConnection* con,
|
||||
{
|
||||
cerr << "*** WARNING[" << m_section
|
||||
<< "]: Already have an inbound connection, rejecting new one" << endl;
|
||||
if (m_debug)
|
||||
{
|
||||
cerr << m_section << " [DEBUG]: existing inbound from "
|
||||
<< m_inbound_con->remoteHost() << ":"
|
||||
<< m_inbound_con->remotePort()
|
||||
<< " ib_hello=" << m_ib_hello_received
|
||||
<< " ib_hb_rx=" << m_ib_hb_rx_cnt
|
||||
<< " new inbound from " << con->remoteHost() << ":"
|
||||
<< con->remotePort() << endl;
|
||||
}
|
||||
con->disconnect();
|
||||
return;
|
||||
}
|
||||
@@ -336,6 +354,14 @@ void TrunkLink::acceptInboundConnection(Async::FramedTcpConnection* con,
|
||||
<< ":" << con->remotePort() << " peer='" << hello.id()
|
||||
<< "' priority=" << m_peer_priority << endl;
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: inbound state: ob_connected="
|
||||
<< m_con.isConnected() << " ob_hello=" << m_ob_hello_received
|
||||
<< " ib_hb_tx=" << m_ib_hb_tx_cnt
|
||||
<< " ib_hb_rx=" << m_ib_hb_rx_cnt << endl;
|
||||
}
|
||||
|
||||
// Send our hello back on the inbound connection
|
||||
sendMsgOnInbound(MsgTrunkHello(m_section, joinPrefixes(m_local_prefix),
|
||||
m_priority, m_secret));
|
||||
@@ -347,11 +373,27 @@ void TrunkLink::onInboundDisconnected(Async::FramedTcpConnection* con,
|
||||
{
|
||||
if (con != m_inbound_con)
|
||||
{
|
||||
if (m_debug)
|
||||
{
|
||||
cerr << m_section << " [DEBUG]: onInboundDisconnected for unknown con "
|
||||
<< con->remoteHost() << ":" << con->remotePort()
|
||||
<< " (m_inbound_con="
|
||||
<< (m_inbound_con ? "set" : "null") << ")" << endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cout << m_section << ": Inbound trunk connection lost" << endl;
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: inbound lost: ib_hello=" << m_ib_hello_received
|
||||
<< " ib_hb_rx=" << m_ib_hb_rx_cnt
|
||||
<< " ob_connected=" << m_con.isConnected()
|
||||
<< " ob_hello=" << m_ob_hello_received
|
||||
<< " peer_active_tgs=" << m_peer_active_tgs.size() << endl;
|
||||
}
|
||||
|
||||
m_inbound_con = nullptr;
|
||||
m_ib_hello_received = false;
|
||||
m_ib_hb_tx_cnt = 0;
|
||||
@@ -434,6 +476,13 @@ void TrunkLink::onConnected(void)
|
||||
cout << m_section << ": Outbound connected to " << m_con.remoteHost()
|
||||
<< ":" << m_con.remotePort() << endl;
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: outbound up: ib_connected="
|
||||
<< (m_inbound_con != nullptr) << " ib_hello=" << m_ib_hello_received
|
||||
<< " sending hello with priority=" << m_priority << endl;
|
||||
}
|
||||
|
||||
m_ob_hello_received = false;
|
||||
m_ob_hb_tx_cnt = HEARTBEAT_TX_CNT_RESET;
|
||||
m_ob_hb_rx_cnt = HEARTBEAT_RX_CNT_RESET;
|
||||
@@ -450,6 +499,14 @@ void TrunkLink::onDisconnected(TcpConnection* con,
|
||||
cout << m_section << ": Outbound disconnected: "
|
||||
<< TcpConnection::disconnectReasonStr(reason) << endl;
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: outbound lost: ob_hello=" << m_ob_hello_received
|
||||
<< " ob_hb_rx=" << m_ob_hb_rx_cnt
|
||||
<< " ib_connected=" << (m_inbound_con != nullptr)
|
||||
<< " ib_hello=" << m_ib_hello_received << endl;
|
||||
}
|
||||
|
||||
m_ob_hello_received = false;
|
||||
m_ob_hb_tx_cnt = 0;
|
||||
m_ob_hb_rx_cnt = 0;
|
||||
@@ -504,6 +561,12 @@ void TrunkLink::onFrameReceived(FramedTcpConnection* con,
|
||||
m_ob_hb_rx_cnt = HEARTBEAT_RX_CNT_RESET;
|
||||
}
|
||||
|
||||
if (m_debug && header.type() != MsgTrunkHeartbeat::TYPE)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: rx " << (is_inbound ? "IB" : "OB")
|
||||
<< " type=" << header.type() << " len=" << data.size() << endl;
|
||||
}
|
||||
|
||||
switch (header.type())
|
||||
{
|
||||
case MsgTrunkHeartbeat::TYPE:
|
||||
@@ -574,6 +637,14 @@ void TrunkLink::handleMsgTrunkHello(std::istream& is)
|
||||
<< "' local_prefix=" << msg.localPrefix()
|
||||
<< " priority=" << m_peer_priority
|
||||
<< " (authenticated)" << endl;
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: hello done: ob_hello=" << m_ob_hello_received
|
||||
<< " ib_connected=" << (m_inbound_con != nullptr)
|
||||
<< " ib_hello=" << m_ib_hello_received
|
||||
<< " isActive=" << isActive() << endl;
|
||||
}
|
||||
} /* TrunkLink::handleMsgTrunkHello */
|
||||
|
||||
|
||||
@@ -710,8 +781,18 @@ void TrunkLink::sendMsg(const ReflectorMsg& msg)
|
||||
}
|
||||
else if (isInboundReady())
|
||||
{
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: tx fallback to IB type="
|
||||
<< msg.type() << endl;
|
||||
}
|
||||
sendMsgOnInbound(msg);
|
||||
}
|
||||
else if (m_debug)
|
||||
{
|
||||
cerr << m_section << " [DEBUG]: tx dropped type=" << msg.type()
|
||||
<< " (no active connection)" << endl;
|
||||
}
|
||||
} /* TrunkLink::sendMsg */
|
||||
|
||||
|
||||
@@ -753,6 +834,11 @@ void TrunkLink::heartbeatTick(Async::Timer* t)
|
||||
{
|
||||
if (--m_ob_hb_tx_cnt == 0)
|
||||
{
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: OB heartbeat tx"
|
||||
<< " ob_hb_rx=" << m_ob_hb_rx_cnt << endl;
|
||||
}
|
||||
sendMsgOnOutbound(MsgTrunkHeartbeat());
|
||||
}
|
||||
if (--m_ob_hb_rx_cnt == 0)
|
||||
@@ -761,6 +847,11 @@ void TrunkLink::heartbeatTick(Async::Timer* t)
|
||||
<< "]: Outbound heartbeat timeout" << endl;
|
||||
m_con.disconnect();
|
||||
}
|
||||
else if (m_debug && m_ob_hb_rx_cnt <= 5)
|
||||
{
|
||||
cerr << m_section << " [DEBUG]: OB heartbeat rx countdown: "
|
||||
<< m_ob_hb_rx_cnt << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Inbound heartbeat
|
||||
@@ -768,6 +859,11 @@ void TrunkLink::heartbeatTick(Async::Timer* t)
|
||||
{
|
||||
if (--m_ib_hb_tx_cnt == 0)
|
||||
{
|
||||
if (m_debug)
|
||||
{
|
||||
cout << m_section << " [DEBUG]: IB heartbeat tx"
|
||||
<< " ib_hb_rx=" << m_ib_hb_rx_cnt << endl;
|
||||
}
|
||||
sendMsgOnInbound(MsgTrunkHeartbeat());
|
||||
}
|
||||
if (--m_ib_hb_rx_cnt == 0)
|
||||
@@ -776,6 +872,11 @@ void TrunkLink::heartbeatTick(Async::Timer* t)
|
||||
<< "]: Inbound heartbeat timeout" << endl;
|
||||
m_inbound_con->disconnect();
|
||||
}
|
||||
else if (m_debug && m_ib_hb_rx_cnt <= 5)
|
||||
{
|
||||
cerr << m_section << " [DEBUG]: IB heartbeat rx countdown: "
|
||||
<< m_ib_hb_rx_cnt << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Prune expired peer interest entries
|
||||
|
||||
@@ -140,6 +140,7 @@ class TrunkLink : public sigc::trackable
|
||||
Reflector* m_reflector;
|
||||
Async::Config& m_cfg;
|
||||
std::string m_section;
|
||||
bool m_debug = false;
|
||||
std::string m_peer_host;
|
||||
uint16_t m_peer_port;
|
||||
std::string m_secret;
|
||||
|
||||
@@ -94,6 +94,7 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py
|
||||
#
|
||||
#LOCAL_PREFIX=1
|
||||
#TRUNK_LISTEN_PORT=5302
|
||||
#TRUNK_DEBUG=0 # verbose trunk logging (high log volume — disable after diagnosis)
|
||||
|
||||
#[TRUNK_2]
|
||||
#HOST=reflector-b.example.com
|
||||
|
||||
Reference in new issue
Block a user