diff --git a/src/routing_layer/topo_group_connect.c b/src/routing_layer/topo_group_connect.c index ddb957d3..6f572be6 100644 --- a/src/routing_layer/topo_group_connect.c +++ b/src/routing_layer/topo_group_connect.c @@ -260,8 +260,16 @@ static void tgc_phase1_timeout(void* arg) { } u_free(ids); - for (int i = 0; i < gc->handle_count; i++) { conn_mgr_close(gc->handles[i]); gc->handles[i] = NULL; } - gc->handle_count = 0; + int remaining = 0; + for (int i = 0; i < gc->handle_count; i++) { + struct CONN_MGR_HANDLE* h = gc->handles[i]; + if (h && conn_mgr_get_conn(h) != NULL) { + gc->handles[remaining++] = h; + } else { + if (h) conn_mgr_close(h); + } + } + gc->handle_count = remaining; if (gc->connected_count > 0) { DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s: Phase1 done — %d connected, skipping Phase 2", TGC_ID, gc->connected_count);