From 98e747fa3d4cc2f9dcf68a873b8c45a8e7d4af98 Mon Sep 17 00:00:00 2001 From: Leonardo Cencetti <37414873+leocencetti@users.noreply.github.com> Date: Sat, 21 Nov 2026 16:44:20 +0100 Subject: [PATCH] fix(zenoh): fail the topic setup when a declaration fails (#29924) A subscriber that could not be declared called exit(-1). That ended the module task but left the zenoh-pico tasks running, so the session stayed up with nothing bridged and `zenoh status` still reported it as connected. Return the error instead, and fail the topic setup when a subscriber or publisher declaration fails. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Leonardo Cencetti --- src/modules/zenoh/subscribers/zenoh_subscriber.cpp | 4 ++-- src/modules/zenoh/zenoh.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/zenoh/subscribers/zenoh_subscriber.cpp b/src/modules/zenoh/subscribers/zenoh_subscriber.cpp index 47733906eb4..189462abdd0 100644 --- a/src/modules/zenoh/subscribers/zenoh_subscriber.cpp +++ b/src/modules/zenoh/subscribers/zenoh_subscriber.cpp @@ -78,8 +78,8 @@ int Zenoh_Subscriber::declare_subscriber(z_owned_session_t s, const char *keyexp z_view_keyexpr_from_str(&ke, keyexpr); if (z_declare_subscriber(z_loan(s), &_sub, z_loan(ke), z_closure_sample_move(&callback), nullptr) < 0) { - printf("Unable to declare subscriber.\n"); - exit(-1); + PX4_ERR("Unable to declare subscriber for %s", keyexpr); + return -1; } return 0; diff --git a/src/modules/zenoh/zenoh.cpp b/src/modules/zenoh/zenoh.cpp index 2274368fc21..e475cf14d54 100644 --- a/src/modules/zenoh/zenoh.cpp +++ b/src/modules/zenoh/zenoh.cpp @@ -392,7 +392,10 @@ int ZENOH::setupTopics(px4_pollfd_struct_t *pfds) if (rihs_hash != nullptr && _zenoh_subscribers[i] != nullptr && generate_rmw_zenoh_topic_keyexpr(topic, rihs_hash, type, keyexpr) > 0) { - _zenoh_subscribers[i]->declare_subscriber(_s, keyexpr); + if (_zenoh_subscribers[i]->declare_subscriber(_s, keyexpr) < 0) { + return -1; + } + #ifdef CONFIG_ZENOH_RMW_LIVELINESS if (generate_rmw_zenoh_topic_liveliness_keyexpr(&self_id, topic, rihs_hash, type, keyexpr, "MS") > 0) { @@ -473,10 +476,15 @@ int ZENOH::setupTopics(px4_pollfd_struct_t *pfds) if (rihs_hash && _zenoh_publishers[i] != nullptr && generate_rmw_zenoh_topic_keyexpr(topic, rihs_hash, type, keyexpr) > 0) { #ifdef CONFIG_ZENOH_PUB_OPTION_OVERRIDE - _zenoh_publishers[i]->declare_publisher(_s, keyexpr, (uint8_t *)&_px4_guid, &pub_opts); + z_publisher_options_t *opts = &pub_opts; #else - _zenoh_publishers[i]->declare_publisher(_s, keyexpr, (uint8_t *)&_px4_guid, &global_opts); + z_publisher_options_t *opts = &global_opts; #endif + + if (_zenoh_publishers[i]->declare_publisher(_s, keyexpr, (uint8_t *)&_px4_guid, opts) < 0) { + return -1; + } + _zenoh_publishers[i]->setPollFD(&pfds[i]); #ifdef CONFIG_ZENOH_RMW_LIVELINESS