From 3766c61df6a0a2d6d71cc2b74260276c726b1dc1 Mon Sep 17 00:00:00 2001 From: Yadunund Date: Sat, 21 Sep 2024 07:21:33 +0800 Subject: [PATCH 1/4] Document issue with shutdown Signed-off-by: Yadunund --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 9a4097eb..c273a4d7 100644 --- a/README.md +++ b/README.md @@ -131,3 +131,26 @@ For instance: - `RUST_LOG=zenoh=debug` activates all the debug logs. For more information on the `RUST_LOG` syntax, see https://docs.rs/env_logger/latest/env_logger/#enabling-logging. + +### Known Issues + +### Crash when program terminates + +When a program terminates, global and static objects are destructed in the reverse order of their +construction. The `Thread Local Storage` is one such entity which the `tokio` runtime in Zenoh +uses. If the Zenoh session is closed after this entity is cleared, it causes a panic like seen below. + +``` +thread '' panicked at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/thread/local.rs:262:26: +cannot access a Thread Local Storage value during or after destruction: AccessError +``` + +This can happen with `rmw_zenoh` if a ROS 2 node's `Context` is not shutdown explicitly before the +program terminates. In this scenario, the `Context` will be shutdown inside the `Context`'s destructor +which then closes the Zenoh session. Since the ordering of global/static objects is not clear, this +often leads to the above panic. + +The recommendation is to ensure the `Context` is shutdown before a program terminates. +For example, when using `rclcpp`, ensure `rclcpp::shutdown()` is invoked the program exits. + +For more details, see https://github.com/ros2/rmw_zenoh/issues/170. From 33c4e43add57c2ef5dea1973f66ed540424ac8dd Mon Sep 17 00:00:00 2001 From: Yadu Date: Tue, 1 Oct 2024 11:25:01 -0700 Subject: [PATCH 2/4] Update README.md Co-authored-by: Chris Lalancette Signed-off-by: Yadu --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c273a4d7..cb5bcafb 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,9 @@ For more information on the `RUST_LOG` syntax, see https://docs.rs/env_logger/la ### Crash when program terminates When a program terminates, global and static objects are destructed in the reverse order of their -construction. The `Thread Local Storage` is one such entity which the `tokio` runtime in Zenoh -uses. If the Zenoh session is closed after this entity is cleared, it causes a panic like seen below. +construction. +The `Thread Local Storage` is one such entity which the `tokio` runtime in Zenoh uses. +If the Zenoh session is closed after this entity is cleared, it causes a panic like seen below. ``` thread '' panicked at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/thread/local.rs:262:26: From 3a419f9a8aa475799a6a84c9ece2146c3600a399 Mon Sep 17 00:00:00 2001 From: Yadu Date: Tue, 1 Oct 2024 11:25:23 -0700 Subject: [PATCH 3/4] Update README.md Co-authored-by: Chris Lalancette Signed-off-by: Yadu --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb5bcafb..2e930540 100644 --- a/README.md +++ b/README.md @@ -146,10 +146,10 @@ thread '' panicked at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/l cannot access a Thread Local Storage value during or after destruction: AccessError ``` -This can happen with `rmw_zenoh` if a ROS 2 node's `Context` is not shutdown explicitly before the -program terminates. In this scenario, the `Context` will be shutdown inside the `Context`'s destructor -which then closes the Zenoh session. Since the ordering of global/static objects is not clear, this -often leads to the above panic. +This can happen with `rmw_zenoh` if the ROS 2 `Context` is not shutdown explicitly before the +program terminates. +In this scenario, the `Context` will be shutdown inside the `Context`'s destructor which then closes the Zenoh session. +Since the ordering of global/static objects is not defined, this often leads to the above panic. The recommendation is to ensure the `Context` is shutdown before a program terminates. For example, when using `rclcpp`, ensure `rclcpp::shutdown()` is invoked the program exits. From 19f709fb93d4d48f886c739c2b0418348952539a Mon Sep 17 00:00:00 2001 From: Yadu Date: Tue, 1 Oct 2024 11:25:37 -0700 Subject: [PATCH 4/4] Update README.md Co-authored-by: Chris Lalancette Signed-off-by: Yadu --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e930540..164fe0f8 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ In this scenario, the `Context` will be shutdown inside the `Context`'s destruct Since the ordering of global/static objects is not defined, this often leads to the above panic. The recommendation is to ensure the `Context` is shutdown before a program terminates. -For example, when using `rclcpp`, ensure `rclcpp::shutdown()` is invoked the program exits. +One way to ensure this is to call `rclcpp::shutdown()` when the program exits. +Note that composable nodes should *never* call `rclcpp::shutdown()`, as the composable node container will automatically do this. For more details, see https://github.com/ros2/rmw_zenoh/issues/170.