Skip to content

Commit ba1ab30

Browse files
YuanYuYuanJEnoch
andauthored
Bump zenoh to 1.8.0 - 2nd attempt (#964)
* chore(zenoh_cpp_vendor): bump to latest zenoh-c and zenoh-cpp - zenoh-c main: 102df1a3 (2026-04-10) - zenoh-c ROS/rust-1.75: 0193595c (2026-04-07) - zenoh-cpp main: af381b42 (2026-04-10) * fix: close session explicitly in shutdown() to prevent hang on Windows zenoh commit e5db0ce changed session.close() to call wait_callbacks(), which blocks until all in-flight callbacks finish. With the older teardown order, session_.reset() was called while node-level entities (publishers, subscriptions, etc.) still held shared_ptr<Session> refs, so the session wasn't actually destroyed until ~Data() called nodes_.clear() — at which point wait_callbacks() would deadlock against callbacks being concurrently destroyed on Windows. Fix: call session_->close() explicitly in shutdown() before session_.reset(). At shutdown time the spin loop has already exited, so no callbacks are in-flight and wait_callbacks() returns immediately. The session is then marked closed; when the shared_ptr refcount eventually drops to zero during normal rcl teardown, the session destructor finds is_closed()==true and skips the blocking close(). * chore(zenoh_cpp_vendor): restore get_cargo_version.cmake from #945 Extract cargo version detection into a reusable CMake function instead of inlining execute_process, matching the approach from PR #945. * fix: disable ANSI color codes in Zenoh log output (#951) Set RUST_LOG_STYLE=never before initializing the Zenoh logger so that color escape sequences do not leak into captured command output. This fixes YAML parsing failures in ros2param tests where the ESC character was treated as an unacceptable character. The env var is set with overwrite=0 so callers can still override it. * Use zenoh-c commits for Zenoh 1.8.0 + #2493 * Fix synchronization due to changes in undeclare in zenoh 1.8.0 This commit re-applies changes made in #935 , while keeping the explicit call to session_.close() added in rmw_context_impl_s::shutdown() * Use zenoh 2687c5135 eclipse-zenoh/zenoh@2687c51 from branch https://github.com/eclipse-zenoh/zenoh/tree/suppress-admin-err-message-on-session-close based on 1.8.0 plus few fixes, including removal of a error log at closure causing failure of a ros2cli test * revert disable ANSI color codes in Zenoh log output --------- Co-authored-by: Julien Enoch <julien.e@zettascale.tech>
1 parent 0c8fec6 commit ba1ab30

9 files changed

Lines changed: 284 additions & 265 deletions

File tree

rmw_zenoh_cpp/src/detail/rmw_client_data.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,16 @@ ClientData::ClientData(
210210
///=============================================================================
211211
liveliness::TopicInfo ClientData::topic_info() const
212212
{
213-
std::lock_guard<std::recursive_mutex> lock(mutex_);
214213
return entity_->topic_info().value();
215214
}
216215

217216
///=============================================================================
218217
bool ClientData::liveliness_is_valid() const
219218
{
220-
std::lock_guard<std::recursive_mutex> lock(mutex_);
221219
// The z_check function is now internal in zenoh-1.0.0 so we assume
222220
// the liveliness token is still initialized as long as this entity has
223221
// not been shutdown.
224-
return !is_shutdown_;
222+
return !is_shutdown_.load(std::memory_order_acquire);
225223
}
226224

227225
///=============================================================================
@@ -233,7 +231,7 @@ std::array<uint8_t, RMW_GID_STORAGE_SIZE> ClientData::copy_gid() const
233231
///=============================================================================
234232
void ClientData::add_new_reply(std::unique_ptr<ZenohReply> reply)
235233
{
236-
std::lock_guard<std::recursive_mutex> lock(mutex_);
234+
std::lock_guard<std::mutex> lock(mutex_);
237235
const rmw_qos_profile_t adapted_qos_profile =
238236
entity_->topic_info().value().qos_;
239237
if (adapted_qos_profile.history != RMW_QOS_POLICY_HISTORY_KEEP_ALL &&
@@ -265,10 +263,10 @@ rmw_ret_t ClientData::take_response(
265263
void * ros_response,
266264
bool * taken)
267265
{
268-
std::lock_guard<std::recursive_mutex> lock(mutex_);
266+
std::lock_guard<std::mutex> lock(mutex_);
269267
*taken = false;
270268

271-
if (is_shutdown_ || reply_queue_.empty()) {
269+
if (this->is_shutdown() || reply_queue_.empty()) {
272270
// This tells rcl that the check for a new message was done, but no messages have come in yet.
273271
return RMW_RET_OK;
274272
}
@@ -342,8 +340,8 @@ rmw_ret_t ClientData::send_request(
342340
const void * ros_request,
343341
int64_t * sequence_id)
344342
{
345-
std::unique_lock<std::recursive_mutex> lock(mutex_);
346-
if (is_shutdown_) {
343+
std::unique_lock<std::mutex> lock(mutex_);
344+
if (this->is_shutdown()) {
347345
return RMW_RET_OK;
348346
}
349347

@@ -482,15 +480,15 @@ void ClientData::set_on_new_response_callback(
482480
rmw_event_callback_t callback,
483481
const void * user_data)
484482
{
485-
std::lock_guard<std::recursive_mutex> lock(mutex_);
483+
std::lock_guard<std::mutex> lock(mutex_);
486484
data_callback_mgr_.set_callback(user_data, std::move(callback));
487485
}
488486

489487
///=============================================================================
490488
bool ClientData::queue_has_data_and_attach_condition_if_not(
491489
rmw_wait_set_data_t * wait_set_data)
492490
{
493-
std::lock_guard<std::recursive_mutex> lock(mutex_);
491+
std::lock_guard<std::mutex> lock(mutex_);
494492
if (!reply_queue_.empty()) {
495493
return true;
496494
}
@@ -502,7 +500,7 @@ bool ClientData::queue_has_data_and_attach_condition_if_not(
502500
///=============================================================================
503501
bool ClientData::detach_condition_and_queue_is_empty()
504502
{
505-
std::lock_guard<std::recursive_mutex> lock(mutex_);
503+
std::lock_guard<std::mutex> lock(mutex_);
506504
wait_set_data_ = nullptr;
507505

508506
return reply_queue_.empty();
@@ -511,8 +509,10 @@ bool ClientData::detach_condition_and_queue_is_empty()
511509
///=============================================================================
512510
rmw_ret_t ClientData::shutdown()
513511
{
514-
std::lock_guard<std::recursive_mutex> lock(mutex_);
515-
if (is_shutdown_) {
512+
bool expected = false;
513+
if (!is_shutdown_.compare_exchange_strong(expected, true, std::memory_order_acq_rel,
514+
std::memory_order_relaxed))
515+
{
516516
return RMW_RET_OK;
517517
}
518518

@@ -536,16 +536,12 @@ rmw_ret_t ClientData::shutdown()
536536
return RMW_RET_ERROR;
537537
}
538538

539-
sess_.reset();
540-
is_shutdown_ = true;
541-
542539
return RMW_RET_OK;
543540
}
544541

545542
///=============================================================================
546543
bool ClientData::is_shutdown() const
547544
{
548-
std::lock_guard<std::recursive_mutex> lock(mutex_);
549-
return is_shutdown_;
545+
return is_shutdown_.load(std::memory_order_acquire);
550546
}
551547
} // namespace rmw_zenoh_cpp

rmw_zenoh_cpp/src/detail/rmw_client_data.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define DETAIL__RMW_CLIENT_DATA_HPP_
1717

1818
#include <array>
19+
#include <atomic>
1920
#include <cstddef>
2021
#include <cstdint>
2122
#include <deque>
@@ -93,9 +94,6 @@ class ClientData final : public std::enable_shared_from_this<ClientData>
9394
// Detach any attached wait set condition variable, and return whether there is data in the queue.
9495
bool detach_condition_and_queue_is_empty();
9596

96-
// Shutdown this ClientData.
97-
rmw_ret_t shutdown();
98-
9997
// Check if this ClientData is shutdown.
10098
bool is_shutdown() const;
10199

@@ -115,8 +113,11 @@ class ClientData final : public std::enable_shared_from_this<ClientData>
115113
std::shared_ptr<RequestTypeSupport> request_type_support,
116114
std::shared_ptr<ResponseTypeSupport> response_type_support);
117115

116+
// Shutdown this ClientData.
117+
rmw_ret_t shutdown();
118+
118119
// Internal mutex.
119-
mutable std::recursive_mutex mutex_;
120+
mutable std::mutex mutex_;
120121
// The parent node.
121122
const rmw_node_t * rmw_node_;
122123
// The rmw client.
@@ -143,7 +144,7 @@ class ClientData final : public std::enable_shared_from_this<ClientData>
143144
// Sequence number for queries.
144145
size_t sequence_number_;
145146
// Shutdown flag.
146-
bool is_shutdown_;
147+
std::atomic<bool> is_shutdown_;
147148
// Whether the object has ever successfully been initialized.
148149
bool initialized_;
149150
};

0 commit comments

Comments
 (0)