fix(satellite): defer heartbeat until auth; reject hello triggers cleanup
SatelliteLink's heartbeat timer was constructed with the default enabled=true, so it started ticking at connect time. When a hello was rejected, m_con->disconnect() closed the socket but the timer kept running; at the t=10s tx tick it called sendMsg, which hit assert(sock >= 0) in TcpConnection::write and crashed the reflector. TcpConnection::disconnect() intentionally does not emit the disconnected signal (header comment), so the TcpServer's clientDisconnected handler never ran -- the SatelliteLink stayed in m_satellite_con_map with no path to cleanup. TrunkLink avoids this by constructing its heartbeat with enabled=false and enabling it only after auth (TrunkLink.cpp:197); SatelliteLink just missed the pattern. Mirror TrunkLink: construct the heartbeat disabled, enable it after successful authentication in handleMsgPeerHello. On all four rejection branches, fire linkFailed(this) after m_con->disconnect() so the existing onSatelliteLinkFailed -> processSatelliteCleanup path deletes the leaked link. Add test_rejection_does_not_crash_parent regression test that sends a hello with a wrong-for-pinned-id secret, waits past the 10s heartbeat threshold, and confirms /status still responds and shows no phantom satellite entry.
This commit is contained in:
1 parent
f51ead2d7b
commit
d757384c9c
2 files changed
+37
-2
No files matched your search
@@ -90,7 +90,11 @@ SatelliteLink::SatelliteLink(Reflector* reflector,
|
||||
Async::FramedTcpConnection* con)
|
||||
: m_reflector(reflector), m_con(con),
|
||||
m_hello_received(false),
|
||||
m_heartbeat_timer(1000, Timer::TYPE_PERIODIC),
|
||||
// Heartbeat starts disabled; handleMsgPeerHello turns it on after
|
||||
// successful authentication (mirrors TrunkLink). If a hello is
|
||||
// rejected the timer never ticks, so it cannot try to write to a
|
||||
// socket that m_con->disconnect() has already closed.
|
||||
m_heartbeat_timer(1000, Timer::TYPE_PERIODIC, false),
|
||||
m_hb_tx_cnt(HEARTBEAT_TX_CNT_RESET),
|
||||
m_hb_rx_cnt(HEARTBEAT_RX_CNT_RESET)
|
||||
{
|
||||
@@ -287,6 +291,7 @@ void SatelliteLink::handleMsgPeerHello(std::istream& is)
|
||||
{
|
||||
geulog::error("satellite", "Satellite sent empty ID");
|
||||
m_con->disconnect();
|
||||
linkFailed(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -295,6 +300,7 @@ void SatelliteLink::handleMsgPeerHello(std::istream& is)
|
||||
geulog::error("satellite", "Expected ROLE_SATELLITE from '", msg.id(),
|
||||
"' but got role=", (int)msg.role());
|
||||
m_con->disconnect();
|
||||
linkFailed(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -307,6 +313,7 @@ void SatelliteLink::handleMsgPeerHello(std::istream& is)
|
||||
msg.id(), "' (no SECRET_<id>= match and no fallback "
|
||||
"SECRET=) — rejecting");
|
||||
m_con->disconnect();
|
||||
linkFailed(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -316,12 +323,18 @@ void SatelliteLink::handleMsgPeerHello(std::istream& is)
|
||||
"Authentication failed for satellite '", msg.id(),
|
||||
"' (pinned=", (pinned ? "true" : "false"), ")");
|
||||
m_con->disconnect();
|
||||
linkFailed(this);
|
||||
return;
|
||||
}
|
||||
|
||||
m_resolved_secret = secret;
|
||||
m_satellite_id = msg.id();
|
||||
m_hello_received = true;
|
||||
// Now that we're authenticated, start ticking the heartbeat. The
|
||||
// timer is constructed disabled (see ctor) so that a rejected hello
|
||||
// cannot leave it ticking against a socket m_con->disconnect() has
|
||||
// already closed.
|
||||
m_heartbeat_timer.setEnable(true);
|
||||
|
||||
geulog::info("satellite", "Satellite '", m_satellite_id,
|
||||
"' authenticated (pinned=", (pinned ? "true" : "false"), ")");
|
||||
|
||||
Reference in new issue
Block a user