fix(trunk): guard inbound send paths against closed sockets; clean up on heartbeat timeout

A non-paired trunk link could abort the reflector (assert sock >= 0 in
AsyncTcpConnection::write) when an inbound peer was timed out by the
heartbeat. disconnect() closes the socket but does not emit the disconnected
signal, so onInboundDisconnected never runs and m_inbound_con /
m_ib_hello_received stay set. isInboundReady() then reports the dead link as
ready, and the next send — e.g. a MsgPeerTgInterest scheduled by a client
publishing its monitored-TG list — falls through to sendMsgOnInbound and
writes to the closed socket. Reproduces the production abort seen on v1.3.12;
TrunkLink is unchanged through v1.3.13.

- sendMsgOnInbound / isInboundReady: bail when the inbound socket is closed.
- inbound heartbeat timeout: drive the full cleanup (onInboundDisconnected +
  drop the dead connection from the reflector inbound map) so the link
  self-heals and /status is honest, instead of leaving a phantom inbound that
  makes acceptInboundConnection reject every reconnect until restart.
- defense in depth: same isConnected() guard on sendMsgOnOutbound and
  SatelliteLink::sendMsg (currently unreachable, but never write to a closed
  socket regardless).
- tests: test_46 (no crash on timeout + TG-interest send), test_47 (inbound
  recovers after a timeout).
This commit is contained in:
Audric committed 2026-05-21 14:27:27 +02:00
1 parent 8f00196821
commit b268bfe595
5 files changed
+147 -3

No files matched your search

+6
View File
@@ -2482,6 +2482,12 @@ void Reflector::trunkClientConnected(Async::FramedTcpConnection* con)
} /* Reflector::trunkClientConnected */
void Reflector::forgetInboundTrunkConnection(Async::FramedTcpConnection* con)
{
m_trunk_inbound_map.erase(con);
} /* Reflector::forgetInboundTrunkConnection */
void Reflector::trunkClientDisconnected(Async::FramedTcpConnection* con,
Async::FramedTcpConnection::DisconnectReason reason)
{