Skip to content

Commit 0bb90db

Browse files
authored
Fix flakey minimal publisher shutdown (#36)
Signed-off-by: Blake McHale <bmchale@nvidia.com>
1 parent dbae71f commit 0bb90db

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎greenwave_monitor/src/example_greenwave_publisher_main.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ int main(int argc, char * argv[])
2121
{
2222
rclcpp::init(argc, argv);
2323
auto node = std::make_shared<ExampleGreenwavePublisherNode>();
24-
rclcpp::spin(node);
24+
try {
25+
rclcpp::spin(node);
26+
} catch (const rclcpp::exceptions::RCLError & e) {
27+
RCLCPP_DEBUG(
28+
node->get_logger(),
29+
"Context became invalid during spin (expected during shutdown): %s", e.what());
30+
}
2531
rclcpp::shutdown();
2632
return 0;
2733
}

‎greenwave_monitor/src/minimal_publisher_main.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
2-
// Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -22,7 +22,13 @@ int main(int argc, char * argv[])
2222
rclcpp::init(argc, argv);
2323
rclcpp::NodeOptions options;
2424
auto node = std::make_shared<MinimalPublisher>(options);
25-
rclcpp::spin(node);
25+
try {
26+
rclcpp::spin(node);
27+
} catch (const rclcpp::exceptions::RCLError & e) {
28+
RCLCPP_DEBUG(
29+
node->get_logger(),
30+
"Context became invalid during spin (expected during shutdown): %s", e.what());
31+
}
2632
rclcpp::shutdown();
2733
return 0;
2834
}

0 commit comments

Comments
 (0)