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
@@ -102,7 +102,29 @@ class SatelliteSecretsTest(unittest.TestCase):
|
||||
finally:
|
||||
sat.close()
|
||||
|
||||
# 4. Malformed SECRET_<bad.id>= is ignored at startup; the id still
|
||||
# 4. Regression: a rejected hello must not leave a SatelliteLink whose
|
||||
# heartbeat timer keeps ticking against a closed socket. Pre-fix,
|
||||
# the parent asserted in TcpConnection::write ~10s after rejection
|
||||
# (because the heartbeat timer was constructed enabled and never
|
||||
# got disabled when the hello was rejected). Send a bad hello,
|
||||
# wait past the 10s tx-heartbeat threshold, then confirm /status
|
||||
# still responds (i.e. the parent process is alive).
|
||||
def test_rejection_does_not_crash_parent(self):
|
||||
peer = SatellitePeer()
|
||||
peer.connect_satellite()
|
||||
priority = struct.unpack("!I", os.urandom(4))[0]
|
||||
hello = build_trunk_hello(T.SATELLITE_PINNED_ID, "", priority,
|
||||
SAT_SECRET, role=ROLE_SATELLITE)
|
||||
send_frame(peer.sock, hello)
|
||||
peer.close()
|
||||
# Past the t=10s heartbeat tx tick where the pre-fix crash fired.
|
||||
time.sleep(11.0)
|
||||
status = get_status(*_http(PRIMARY))
|
||||
self.assertIsInstance(status, dict, "parent /status not responding")
|
||||
self.assertNotIn(T.SATELLITE_PINNED_ID, status.get("satellites", {}),
|
||||
"phantom satellite entry after rejection")
|
||||
|
||||
# 5. Malformed SECRET_<bad.id>= is ignored at startup; the id still
|
||||
# authenticates via the default fallback.
|
||||
#
|
||||
# We don't grep docker logs for the startup warning here (rolling
|
||||
|
||||
Reference in new issue
Block a user