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:
Audric committed 2026-04-05 11:55:43 +02:00
1 parent 9c359ba507
commit 638d3c527e
8 files changed
+186 -2

No files matched your search

+29 -1
View File
@@ -151,7 +151,35 @@ Cluster TG numbers must not overlap with any `LOCAL_PREFIX` or `REMOTE_PREFIX`.
**Note:** Satellite links are unaffected by cluster TG configuration — they
forward all TGs unconditionally (see [Satellite reflectors](#satellite-reflectors)).
### 3. Add a trunk section per peer
### 3. Trunk debug logging (optional)
Enable verbose trunk logging to diagnose connection issues:
```ini
[GLOBAL]
TRUNK_DEBUG=1
```
When enabled, the reflector logs detailed information about every trunk
connection state change, including:
- Connection and disconnection events with full state (both directions'
hello/heartbeat counters, whether the other direction is up)
- Heartbeat countdown warnings as the RX counter approaches timeout
- Every non-heartbeat frame received, with direction (IB/OB), type, and size
- Send path decisions (outbound, fallback to inbound, or dropped)
- Trunk server peer matching: which sections matched or mismatched on HMAC
secret and prefix, making configuration errors immediately visible
**Warning:** `TRUNK_DEBUG` logs **every audio frame** received over trunk. During
active transmissions this means dozens of lines per second per TG per trunk link
(e.g. ~50 lines/sec with 20ms Opus framing). On a busy reflector with multiple
simultaneous talkers across several trunk peers, this can produce hundreds of
log lines per second and rapidly fill disk. **Do not leave `TRUNK_DEBUG=1`
enabled in production.** Use it only to diagnose a specific issue, then disable
it immediately.
### 4. Add a trunk section per peer
```ini
[TRUNK_2]
+49
View File
@@ -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);
+1
View File
@@ -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;
+102 -1
View File
@@ -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
+1
View File
@@ -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
+2
View File
@@ -50,6 +50,8 @@ Two V2 clients are configured on every reflector:
A satellite server is enabled on reflector-a (port 5303, secret `sat_secret`).
All test configs have `TRUNK_DEBUG=1` enabled for verbose trunk logging during test runs.
### Port Mapping
| Reflector | Client (TCP+UDP) | Trunk (TCP) | HTTP | Satellite |
+1
View File
@@ -24,6 +24,7 @@ def generate_reflector_conf(name: str) -> str:
f"CLUSTER_TGS={cluster_str}",
f"TRUNK_LISTEN_PORT={T.INTERNAL_TRUNK_PORT}",
f"HTTP_SRV_PORT={T.INTERNAL_HTTP_PORT}",
"TRUNK_DEBUG=1",
"",
"[SERVER_CERT]",
f"COMMON_NAME={T.service_name(name)}",