fix: pause router retransmits before clearing ETCP queues on reinit

When etcp_conn_reinit is called, it clears ETCP queues (input_wait_ack
etc.) which frees dgram objects to data_pool. If a router retransmit
timer fires concurrently, it sends through the same conn → normalizer
allocates from corrupted data_pool → SIGSEGV.

Fix: call etcp_router_pause_retrans_for_node() BEFORE etcp_conn_reset()
to cancel retrans timers and free inflight_q entries for all router
connections to the peer. No callbacks, no close notifications —
lightweight pause, router connections stay alive and resume when
ETCP connection comes back up.
This commit is contained in:
Evgeny committed 2026-07-15 15:37:03 +03:00
1 parent e2de3f1b28
commit 678c237eba
3 files changed
+36

No files matched your search

+3
View File
@@ -523,6 +523,9 @@ void etcp_conn_reinit(struct ETCP_CONN* etcp) {// Если сбой в обме
route_ping_cancel_for_conn(topo_groups_get_default(etcp->instance->topo_groups), etcp);
}
// Сбрасываем ретрансмиты роутера ДО очистки ETCP-очередей (избегаем гонки с data_pool)
if (etcp->peer_node_id) etcp_router_pause_retrans_for_node(etcp->instance, etcp->peer_node_id);
// Сбрасываем NAT-статус у всех линков этого соединения
struct ETCP_LINK* l = etcp->links;
while (l) {
+29
View File
@@ -1379,6 +1379,35 @@ void etcp_router_conn_close_async(struct ETCP_ROUTER_CONN* rconn,
router_close_and_notify(rconn);
}
// Reset retransmit state for all router connections to a node
// (no callbacks, no close notifications — lightweight, for conn reinit)
void etcp_router_pause_retrans_for_node(struct UTUN_INSTANCE* inst, uint64_t remote_node_id) {
if (!inst || !inst->router_conns) return;
struct ll_queue* q = inst->router_conns;
for (uint32_t slot = 0; slot < q->hash_size; slot++) {
struct ll_entry* entry = q->hash_table[slot];
while (entry) {
struct ETCP_ROUTER_CONN* rconn = (struct ETCP_ROUTER_CONN*)entry;
if (rconn->remote_node_id == remote_node_id && !rconn->closed) {
if (rconn->retrans_timer) { uasync_cancel_timeout(inst->ua, rconn->retrans_timer); rconn->retrans_timer = NULL; }
if (rconn->inflight_q) {
struct ll_entry* f;
while ((f = queue_data_get(rconn->inflight_q)) != NULL) {
struct ROUTER_INFLIGHT* inf = (struct ROUTER_INFLIGHT*)f;
if (inf->payload) u_free(inf->payload);
u_free(inf);
}
}
rconn->no_ack_count = 0;
rconn->last_ack_changed_tb = get_time_tb();
DEBUG_INFO(DEBUG_CATEGORY_ETCPROUTE, "router: paused retrans for remote=%016llx svc_id=%u",
(unsigned long long)remote_node_id, rconn->svc_id);
}
entry = entry->hash_next;
}
}
}
void etcp_router_conn_close_all_for_node(struct UTUN_INSTANCE* inst, uint64_t remote_node_id) {
if (!inst || !inst->router_conns) return;
// Iterate via hash chains to avoid inf-loop from put-back in FIFO iteration
+4
View File
@@ -196,6 +196,10 @@ void etcp_router_conn_close_async(struct ETCP_ROUTER_CONN* rconn,
void (*on_close_done)(void* arg),
void* close_arg);
// Сбросить ретрансмиты для всех router_conn к узлу (без колбэков, без CLOSE)
// Используется при etcp_conn_reinit чтобы избежать гонки с очисткой ETCP-очередей
void etcp_router_pause_retrans_for_node(struct UTUN_INSTANCE* inst, uint64_t remote_node_id);
// Закрыть все router_conn для указанного remote_node_id (peer умер)
void etcp_router_conn_close_all_for_node(struct UTUN_INSTANCE* inst, uint64_t remote_node_id);