TWIN audio-mirror: stale-inbound cleanup + end-to-end integration test

Two changes:

1. TwinLink::acceptInboundConnection now treats an existing but-disconnected
   m_inbound_con as stale and replaces it with the new arriving connection,
   and wires a disconnected signal on the inbound so m_inbound_con is
   cleared when the remote end goes away. Without these, a partner container
   restart left the surviving twin holding a dead inbound reference that
   kept rejecting the partner's reconnection attempts until the heartbeat
   RX timeout cleared it (5s window, mid-test).

2. New test_08_audio_mirror_between_twins integration test. Reuses ClientPeer
   from test_trunk.py to connect a V2 sender to ref1 and a V2 receiver to
   ref2, both on TG 26201 (prefix 262). Sends audio from ref1's client,
   asserts the receiver on ref2 gets UDP audio + flush datagrams. Proves
   the Phase C1 path end-to-end:
     ref1 client UDP audio
       -> TGHandler.talkerUpdated -> TwinLink.onLocalAudio
       -> MsgTrunkAudio over [TWIN]
       -> ref2.handleMsgTrunkAudio -> broadcastUdpMsg
       -> ref2 client UDP socket.

All 8 tests now pass (36s wall clock).
This commit is contained in:
Audric committed 2026-04-15 22:59:21 +02:00
1 parent 06a2275ee6
commit 81bd3eabf3
2 files changed
+119 -4

No files matched your search

+31 -4
View File
@@ -166,10 +166,23 @@ void TwinLink::acceptInboundConnection(Async::FramedTcpConnection* con,
{
if (m_inbound_con != nullptr)
{
cerr << "*** WARNING[TWIN]: Already have an inbound connection, "
"rejecting new one" << endl;
con->disconnect();
return;
// If the existing inbound's socket is already closed, drop our
// reference to it and accept the new connection — the old one's
// disconnect signal may not have fired yet (e.g. partner crashed
// without a clean FIN).
if (!m_inbound_con->isConnected())
{
cout << "TWIN: replacing stale inbound connection" << endl;
m_inbound_con = nullptr;
m_ib_hello_received = false;
}
else
{
cerr << "*** WARNING[TWIN]: Already have an inbound connection, "
"rejecting new one" << endl;
con->disconnect();
return;
}
}
m_inbound_con = con;
@@ -181,6 +194,20 @@ void TwinLink::acceptInboundConnection(Async::FramedTcpConnection* con,
// Wire inbound frame handler to our message dispatcher
con->frameReceived.connect(mem_fun(*this, &TwinLink::onFrameReceived));
// Wire disconnect handler so we clear m_inbound_con when the remote
// end goes away, otherwise the next reconnect is rejected above.
con->disconnected.connect(
[this](Async::TcpConnection* c,
Async::TcpConnection::DisconnectReason /*reason*/) {
if (m_inbound_con == c)
{
cout << "TWIN: inbound disconnected" << endl;
m_inbound_con = nullptr;
m_ib_hello_received = false;
m_ib_hb_tx_cnt = 0;
m_ib_hb_rx_cnt = 0;
}
});
m_peer_id_received = hello.id();
cout << "TWIN: Accepted inbound from " << con->remoteHost() << ":"