Fix: guard send paths against writing to closed sockets; lower test port bases
Three fixes surfaced while running the E3 integration suite end-to-end: 1. sendMsgOnPairedInbound / sendMsgOnPairedOutbound / TwinLink sendMsgOn* now check isConnected() before calling write(). Without the guard, a heartbeat TX firing between the remote peer dying and our RX-timeout cleanup tripped an "assert sock >= 0" inside Async::TcpConnection::write and crashed the reflector (seen in test_07 as ref2 exiting with SIGSEGV after ref1 was killed). 2. Twin topology trunk_port_base values reduced (45000-48000) so the http-port offset (+3080) stays <= 65535. The earlier 60000-63000 bases produced 66080, which docker compose rejected as an invalid hostPort. 3. Twin reflector names lowercased (refa, refc) to satisfy Docker's image tag constraint (lowercase-only). All 7 integration tests now pass end-to-end: - twin handshake (mutual authenticated hello) - no HMAC/prefix errors on startup - refa's PAIRED=1 trunk reports connected=True - both pair members see TRUNK_IT_DE back to refa - no twin-related ERRORs in startup logs - kill ref2 -> ref1 detects timeout, restart -> re-handshakes - kill ref1 -> refa stays connected to the pair via ref2 (failover)
This commit is contained in:
1 parent
a2b5d448fa
commit
06a2275ee6
4 files changed
+43
-37
No files matched your search
@@ -1378,6 +1378,7 @@ size_t TrunkLink::pairedClientIndex(FramedTcpClient* client) const
|
|||||||
void TrunkLink::sendMsgOnPairedOutbound(size_t idx, const ReflectorMsg& msg)
|
void TrunkLink::sendMsgOnPairedOutbound(size_t idx, const ReflectorMsg& msg)
|
||||||
{
|
{
|
||||||
if (idx >= m_ob_cons.size()) return;
|
if (idx >= m_ob_cons.size()) return;
|
||||||
|
if (!m_ob_cons[idx]->isConnected()) return;
|
||||||
ostringstream ss;
|
ostringstream ss;
|
||||||
ReflectorMsg header(msg.type());
|
ReflectorMsg header(msg.type());
|
||||||
if (!header.pack(ss) || !msg.pack(ss))
|
if (!header.pack(ss) || !msg.pack(ss))
|
||||||
@@ -1405,6 +1406,7 @@ size_t TrunkLink::pairedInboundIndex(Async::FramedTcpConnection* con) const
|
|||||||
void TrunkLink::sendMsgOnPairedInbound(size_t idx, const ReflectorMsg& msg)
|
void TrunkLink::sendMsgOnPairedInbound(size_t idx, const ReflectorMsg& msg)
|
||||||
{
|
{
|
||||||
if (idx >= m_ib_cons.size()) return;
|
if (idx >= m_ib_cons.size()) return;
|
||||||
|
if (!m_ib_cons[idx]->isConnected()) return;
|
||||||
ostringstream ss;
|
ostringstream ss;
|
||||||
ReflectorMsg header(msg.type());
|
ReflectorMsg header(msg.type());
|
||||||
if (!header.pack(ss) || !msg.pack(ss))
|
if (!header.pack(ss) || !msg.pack(ss))
|
||||||
|
|||||||
@@ -566,6 +566,7 @@ bool TwinLink::sendMsg(const ReflectorMsg& msg)
|
|||||||
|
|
||||||
void TwinLink::sendMsgOnOutbound(const ReflectorMsg& msg)
|
void TwinLink::sendMsgOnOutbound(const ReflectorMsg& msg)
|
||||||
{
|
{
|
||||||
|
if (!m_con.isConnected()) return;
|
||||||
ostringstream ss;
|
ostringstream ss;
|
||||||
ReflectorMsg header(msg.type());
|
ReflectorMsg header(msg.type());
|
||||||
if (!header.pack(ss) || !msg.pack(ss))
|
if (!header.pack(ss) || !msg.pack(ss))
|
||||||
@@ -581,7 +582,7 @@ void TwinLink::sendMsgOnOutbound(const ReflectorMsg& msg)
|
|||||||
|
|
||||||
void TwinLink::sendMsgOnInbound(const ReflectorMsg& msg)
|
void TwinLink::sendMsgOnInbound(const ReflectorMsg& msg)
|
||||||
{
|
{
|
||||||
if (m_inbound_con == nullptr) return;
|
if (m_inbound_con == nullptr || !m_inbound_con->isConnected()) return;
|
||||||
ostringstream ss;
|
ostringstream ss;
|
||||||
ReflectorMsg header(msg.type());
|
ReflectorMsg header(msg.type());
|
||||||
if (!header.pack(ss) || !msg.pack(ss))
|
if (!header.pack(ss) || !msg.pack(ss))
|
||||||
|
|||||||
+26
-26
@@ -5,12 +5,12 @@ Verifies the TWIN handshake, PAIRED trunk wiring, talker-state mirroring via
|
|||||||
log inspection, and recovery after container failure.
|
log inspection, and recovery after container failure.
|
||||||
|
|
||||||
Topology used: TWIN (generate_configs.py --topology twin)
|
Topology used: TWIN (generate_configs.py --topology twin)
|
||||||
- reflector-refA (IT, LOCAL_PREFIX=222)
|
- reflector-refa (IT, LOCAL_PREFIX=222)
|
||||||
- reflector-ref1 (DE twin 1, LOCAL_PREFIX=262, [TWIN] partner=ref2)
|
- reflector-ref1 (DE twin 1, LOCAL_PREFIX=262, [TWIN] partner=ref2)
|
||||||
- reflector-ref2 (DE twin 2, LOCAL_PREFIX=262, [TWIN] partner=ref1)
|
- reflector-ref2 (DE twin 2, LOCAL_PREFIX=262, [TWIN] partner=ref1)
|
||||||
- reflector-refC (extra peer, LOCAL_PREFIX=333)
|
- reflector-refc (extra peer, LOCAL_PREFIX=333)
|
||||||
|
|
||||||
refA connects to ref1 AND ref2 via a single PAIRED=1 trunk section (TRUNK_IT_DE).
|
refa connects to ref1 AND ref2 via a single PAIRED=1 trunk section (TRUNK_IT_DE).
|
||||||
ref1 and ref2 maintain a direct [TWIN] link for state mirroring.
|
ref1 and ref2 maintain a direct [TWIN] link for state mirroring.
|
||||||
|
|
||||||
Requires: Python 3.7+, stdlib only (+ topology.py from this directory).
|
Requires: Python 3.7+, stdlib only (+ topology.py from this directory).
|
||||||
@@ -138,17 +138,17 @@ class TestTwinIntegration(unittest.TestCase):
|
|||||||
sys.stderr.write(f"\r\033[K {G}\u2714{RST} Twin reflectors up\n")
|
sys.stderr.write(f"\r\033[K {G}\u2714{RST} Twin reflectors up\n")
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
# Wait for trunk connections between refA↔ref1 and refA↔ref2
|
# Wait for trunk connections between refa↔ref1 and refa↔ref2
|
||||||
sys.stderr.write(f" {D}waiting for trunk mesh...{RST}")
|
sys.stderr.write(f" {D}waiting for trunk mesh...{RST}")
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
# refA has TRUNK_IT_DE (PAIRED=1 → ref1 + ref2)
|
# refa has TRUNK_IT_DE (PAIRED=1 → ref1 + ref2)
|
||||||
wait_for_trunk_connected(*_http("refA"), "TRUNK_IT_DE", timeout=30.0)
|
wait_for_trunk_connected(*_http("refa"), "TRUNK_IT_DE", timeout=30.0)
|
||||||
# ref1 and ref2 each have TRUNK_IT_DE back to refA
|
# ref1 and ref2 each have TRUNK_IT_DE back to refa
|
||||||
wait_for_trunk_connected(*_http("ref1"), "TRUNK_IT_DE", timeout=30.0)
|
wait_for_trunk_connected(*_http("ref1"), "TRUNK_IT_DE", timeout=30.0)
|
||||||
wait_for_trunk_connected(*_http("ref2"), "TRUNK_IT_DE", timeout=30.0)
|
wait_for_trunk_connected(*_http("ref2"), "TRUNK_IT_DE", timeout=30.0)
|
||||||
# refC links
|
# refc links
|
||||||
wait_for_trunk_connected(*_http("refA"), "TRUNK_IT_C", timeout=30.0)
|
wait_for_trunk_connected(*_http("refa"), "TRUNK_IT_C", timeout=30.0)
|
||||||
wait_for_trunk_connected(*_http("refC"), "TRUNK_IT_C", timeout=30.0)
|
wait_for_trunk_connected(*_http("refc"), "TRUNK_IT_C", timeout=30.0)
|
||||||
sys.stderr.write(f"\r\033[K {G}\u2714{RST} Trunk mesh connected\n")
|
sys.stderr.write(f"\r\033[K {G}\u2714{RST} Trunk mesh connected\n")
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
@@ -203,33 +203,33 @@ class TestTwinIntegration(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Test 3: PAIRED trunk — refA connected to BOTH ref1 and ref2
|
# Test 3: PAIRED trunk — refa connected to BOTH ref1 and ref2
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def test_03_paired_trunk_both_partners_connected(self):
|
def test_03_paired_trunk_both_partners_connected(self):
|
||||||
"""refA's TRUNK_IT_DE (PAIRED=1) reports connected=True.
|
"""refa's TRUNK_IT_DE (PAIRED=1) reports connected=True.
|
||||||
|
|
||||||
This confirms that TrunkLink with PAIRED=1 and two peer hosts
|
This confirms that TrunkLink with PAIRED=1 and two peer hosts
|
||||||
reaches the 'active' state after both outbound connections complete
|
reaches the 'active' state after both outbound connections complete
|
||||||
their handshake (or at least one, since isActive() returns true
|
their handshake (or at least one, since isActive() returns true
|
||||||
when either outbound or inbound is ready).
|
when either outbound or inbound is ready).
|
||||||
"""
|
"""
|
||||||
status_a = get_status(*_http("refA"))
|
status_a = get_status(*_http("refa"))
|
||||||
trunk = status_a.get("trunks", {}).get("TRUNK_IT_DE", None)
|
trunk = status_a.get("trunks", {}).get("TRUNK_IT_DE", None)
|
||||||
self.assertIsNotNone(trunk,
|
self.assertIsNotNone(trunk,
|
||||||
"TRUNK_IT_DE not present in refA /status. "
|
"TRUNK_IT_DE not present in refa /status. "
|
||||||
"Was the twin topology generated and docker-compose started?")
|
"Was the twin topology generated and docker-compose started?")
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
trunk.get("connected", False),
|
trunk.get("connected", False),
|
||||||
f"TRUNK_IT_DE on refA is not connected. trunk status: {trunk}",
|
f"TRUNK_IT_DE on refa is not connected. trunk status: {trunk}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Test 4: PAIRED trunk — both pair members see refA as connected
|
# Test 4: PAIRED trunk — both pair members see refa as connected
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def test_04_paired_trunk_pair_members_see_refa(self):
|
def test_04_paired_trunk_pair_members_see_refa(self):
|
||||||
"""ref1 and ref2 each see their TRUNK_IT_DE section as connected.
|
"""ref1 and ref2 each see their TRUNK_IT_DE section as connected.
|
||||||
|
|
||||||
Confirms the return leg (pair member → refA) is also established.
|
Confirms the return leg (pair member → refa) is also established.
|
||||||
"""
|
"""
|
||||||
for name in ("ref1", "ref2"):
|
for name in ("ref1", "ref2"):
|
||||||
status = get_status(*_http(name))
|
status = get_status(*_http(name))
|
||||||
@@ -362,17 +362,17 @@ class TestTwinIntegration(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Test 7: PAIRED trunk failover — kill ref1, refA still routes via ref2
|
# Test 7: PAIRED trunk failover — kill ref1, refa still routes via ref2
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def test_07_paired_trunk_failover(self):
|
def test_07_paired_trunk_failover(self):
|
||||||
"""Killing ref1 should not disconnect refA from the DE twin pair.
|
"""Killing ref1 should not disconnect refa from the DE twin pair.
|
||||||
|
|
||||||
refA uses PAIRED=1 with HOST=reflector-ref1,reflector-ref2. When
|
refa uses PAIRED=1 with HOST=reflector-ref1,reflector-ref2. When
|
||||||
ref1 goes down, refA must still be able to exchange traffic with ref2
|
ref1 goes down, refa must still be able to exchange traffic with ref2
|
||||||
(TrunkLink D2 sticky fallback / isActive() via any live connection).
|
(TrunkLink D2 sticky fallback / isActive() via any live connection).
|
||||||
|
|
||||||
Verification: after killing ref1 and waiting for the heartbeat RX
|
Verification: after killing ref1 and waiting for the heartbeat RX
|
||||||
timeout (~15s), refA's TRUNK_IT_DE status must still report
|
timeout (~15s), refa's TRUNK_IT_DE status must still report
|
||||||
connected=True (served by the ref2 connection).
|
connected=True (served by the ref2 connection).
|
||||||
"""
|
"""
|
||||||
# Step 1: kill ref1
|
# Step 1: kill ref1
|
||||||
@@ -389,10 +389,10 @@ class TestTwinIntegration(unittest.TestCase):
|
|||||||
# Heartbeat TX interval is 10s, RX timeout is 15s → allow 20s.
|
# Heartbeat TX interval is 10s, RX timeout is 15s → allow 20s.
|
||||||
time.sleep(20.0)
|
time.sleep(20.0)
|
||||||
|
|
||||||
# Step 3: refA must still report the trunk as connected (via ref2)
|
# Step 3: refa must still report the trunk as connected (via ref2)
|
||||||
def refa_still_connected():
|
def refa_still_connected():
|
||||||
try:
|
try:
|
||||||
status = get_status(*_http("refA"))
|
status = get_status(*_http("refa"))
|
||||||
return status.get("trunks", {}).get(
|
return status.get("trunks", {}).get(
|
||||||
"TRUNK_IT_DE", {}).get("connected", False)
|
"TRUNK_IT_DE", {}).get("connected", False)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -402,7 +402,7 @@ class TestTwinIntegration(unittest.TestCase):
|
|||||||
refa_still_connected,
|
refa_still_connected,
|
||||||
timeout=10.0,
|
timeout=10.0,
|
||||||
interval=1.0,
|
interval=1.0,
|
||||||
msg="refA TRUNK_IT_DE lost connectivity after killing ref1; "
|
msg="refa TRUNK_IT_DE lost connectivity after killing ref1; "
|
||||||
"expected ref2 to keep the paired link active",
|
"expected ref2 to keep the paired link active",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ class TestTwinIntegration(unittest.TestCase):
|
|||||||
# Also wait for trunk re-establishment
|
# Also wait for trunk re-establishment
|
||||||
wait_for_trunk_connected(*_http("ref1"), "TRUNK_IT_DE",
|
wait_for_trunk_connected(*_http("ref1"), "TRUNK_IT_DE",
|
||||||
timeout=30.0)
|
timeout=30.0)
|
||||||
wait_for_trunk_connected(*_http("refA"), "TRUNK_IT_DE",
|
wait_for_trunk_connected(*_http("refa"), "TRUNK_IT_DE",
|
||||||
timeout=30.0)
|
timeout=30.0)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
+13
-10
@@ -122,7 +122,7 @@ def first_prefix(prefixes) -> str:
|
|||||||
# to select this topology without touching the default above.
|
# to select this topology without touching the default above.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
# 4-reflector mesh: refA (Italy), ref1+ref2 (Germany twin pair), refC (extra)
|
# 4-reflector mesh: refa (Italy), ref1+ref2 (Germany twin pair), refc (extra)
|
||||||
#
|
#
|
||||||
# Keys:
|
# Keys:
|
||||||
# prefix : list of owned prefixes
|
# prefix : list of owned prefixes
|
||||||
@@ -131,10 +131,13 @@ def first_prefix(prefixes) -> str:
|
|||||||
# redis : enable Redis config store (optional)
|
# redis : enable Redis config store (optional)
|
||||||
TWIN_REFLECTORS = {
|
TWIN_REFLECTORS = {
|
||||||
# name prefixes port-base notes
|
# name prefixes port-base notes
|
||||||
"refA": {"prefix": ["222"], "trunk_port_base": 60000}, # Italy
|
# Port layout: client=base+300, trunk=base+302, twin=base+304, http=base+3080
|
||||||
"ref1": {"prefix": ["262"], "trunk_port_base": 61000, "twin_of": "ref2"}, # DE twin 1
|
# Must keep http port <= 65535, so base <= ~62000.
|
||||||
"ref2": {"prefix": ["262"], "trunk_port_base": 62000, "twin_of": "ref1"}, # DE twin 2
|
# Names must be lowercase (Docker image tag constraint).
|
||||||
"refC": {"prefix": ["333"], "trunk_port_base": 63000}, # extra peer
|
"refa": {"prefix": ["222"], "trunk_port_base": 45000}, # Italy
|
||||||
|
"ref1": {"prefix": ["262"], "trunk_port_base": 46000, "twin_of": "ref2"}, # DE twin 1
|
||||||
|
"ref2": {"prefix": ["262"], "trunk_port_base": 47000, "twin_of": "ref1"}, # DE twin 2
|
||||||
|
"refc": {"prefix": ["333"], "trunk_port_base": 48000}, # extra peer
|
||||||
}
|
}
|
||||||
|
|
||||||
# Explicit trunk list for the twin topology.
|
# Explicit trunk list for the twin topology.
|
||||||
@@ -145,24 +148,24 @@ TWIN_REFLECTORS = {
|
|||||||
# pair_members : the subset of peers that form the twin pair (needed to split sides)
|
# pair_members : the subset of peers that form the twin pair (needed to split sides)
|
||||||
#
|
#
|
||||||
# For a paired trunk the rule is:
|
# For a paired trunk the rule is:
|
||||||
# - non-pair side (refA): [TRUNK_IT_DE] HOST=ref1,ref2 PAIRED=1
|
# - non-pair side (refa): [TRUNK_IT_DE] HOST=ref1,ref2 PAIRED=1
|
||||||
# - pair members (ref1, ref2): [TRUNK_IT_DE] HOST=refA (normal, no PAIRED)
|
# - pair members (ref1, ref2): [TRUNK_IT_DE] HOST=refa (normal, no PAIRED)
|
||||||
TWIN_TRUNKS = [
|
TWIN_TRUNKS = [
|
||||||
{
|
{
|
||||||
"name": "IT_DE",
|
"name": "IT_DE",
|
||||||
"peers": ["refA", "ref1", "ref2"],
|
"peers": ["refa", "ref1", "ref2"],
|
||||||
"paired": True,
|
"paired": True,
|
||||||
"pair_members": ["ref1", "ref2"],
|
"pair_members": ["ref1", "ref2"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "IT_C",
|
"name": "IT_C",
|
||||||
"peers": ["refA", "refC"],
|
"peers": ["refa", "refc"],
|
||||||
"paired": False,
|
"paired": False,
|
||||||
"pair_members": [],
|
"pair_members": [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DE_C",
|
"name": "DE_C",
|
||||||
"peers": ["ref1", "ref2", "refC"],
|
"peers": ["ref1", "ref2", "refc"],
|
||||||
"paired": True,
|
"paired": True,
|
||||||
"pair_members": ["ref1", "ref2"],
|
"pair_members": ["ref1", "ref2"],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user