geometry2 icon indicating copy to clipboard operation
geometry2 copied to clipboard

Catching lookupTransform()

Open moritzboeker opened this issue 7 months ago • 5 comments

Description

We had a scenario, in which a point cloud had timestamps sometimes older than 10 seconds. This caused problems for the Spatio Temporal Voxel Layer, because when calling lookupTransform(), canTransform(), doTransform() it couldn't retrieve a transform for a point cloud this old since the tf buffer already timed out.

I didn't create an issue yet. Fixes # (issue)

Did you use Generative AI?

Claude Code Sonnet 4.6

Additional Information

The original core dump was

#0  __pthread_kill_implementation (threadid=281472917954528, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x0000ffffba3a7670 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  0x0000ffffba35cb3c in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x0000ffffba347e00 in __GI_abort () at ./stdlib/abort.c:79
#4  0x0000ffffba5cd4d8 in __gnu_cxx::__verbose_terminate_handler() () from /lib/aarch64-linux-gnu/libstdc++.so.6
#5  0x0000ffffba5ca570 [PAC] in ?? () from /lib/aarch64-linux-gnu/libstdc++.so.6
#6  0x0000ffffba5c0e04 [PAC] in std::terminate() () from /lib/aarch64-linux-gnu/libstdc++.so.6
#7  0x0000ffffba5ca908 [PAC] in __cxa_throw () from /lib/aarch64-linux-gnu/libstdc++.so.6
#8  0x0000ffffb94ee804 [PAC] in tf2::BufferCore::lookupTransformImpl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > const&, tf2::Transform&, std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >&) const () from /opt/ros/jazzy/lib/libtf2.so
#9  0x0000ffffb94ee86c [PAC] in tf2::BufferCore::lookupTransform(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > const&) const ()
   from /opt/ros/jazzy/lib/libtf2.so
#10 0x0000ffffb9410d08 [PAC] in tf2_ros::Buffer::waitForTransform(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > const&, std::chrono::duration<long, std::ratio<1l, 1000000000l> > const&, std::function<void (tf2_ros::TransformStampedFuture const&)>) () from /opt/ros/jazzy/lib/libtf2_ros.so
#11 0x0000ffff8af9ba80 [PAC] in ?? () from /opt/ros/jazzy/lib/libspatio_temporal_voxel_layer_core.so
#12 0x0000ffff8afc12fc [PAC] in ?? () from /opt/ros/jazzy/lib/libspatio_temporal_voxel_layer_core.so
#13 0x0000ffff8afac398 [PAC] in std::_Function_handler<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>), message_filters::Subscriber<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, rclcpp_lifecycle::LifecycleNode>::subscribe(rclcpp_lifecycle::LifecycleNode*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rmw_qos_profile_s, rclcpp::SubscriptionOptionsWithAllocator<std::allocator<void> >)::{lambda(std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>)#1}>::_M_invoke(std::_Any_data const&, std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>&&) () from /opt/ros/jazzy/lib/libspatio_temporal_voxel_layer_core.so
#14 0x0000ffff8afc826c [PAC] in std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(rclcpp::AnySubscriptionCallback<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, std::allocator<void> >::dispatch<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >(std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >, rclcpp::MessageInfo const&)::{lambda(auto:1&&)#1}&&, std::variant<std::function<void (sensor_msgs::msg::PointCloud2_<std::allocator<void> > const&)>, std::function<void (sensor_msgs::msg::PointCloud2_<std::allocator<void> > const&, rclcpp::MessageInfo const&)>, std::function<void (rclcpp::SerializedMessage const&)>, std::function<void (rclcpp::SerializedMessage const&, rclcpp::MessageInfo const&)>, std::function<void (std::unique_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, std::default_delete<sensor_msgs::msg::PointCloud2_<std::allocator<void> > > >)>, std::function<void (std::unique_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, std::default_delete<sensor_msgs::msg::PointCloud2_<std::allocator<void> > > >, rclcpp::MessageInfo const&)>, std::function<void (std::unique_ptr<rclcpp::SerializedMessage, std::default_delete<rclcpp::SerializedMessage> >)>, std::function<void (std::unique_ptr<rclcpp::SerializedMessage, std::default_delete<rclcpp::SerializedMessage> >, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const>)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const>, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const> const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const> const&, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const> const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const> const&, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage>)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage>, rclcpp::MessageInfo const&)> >&)>, std::integer_sequence<unsigned long, 8ul> >::__visit_invoke(rclcpp::AnySubscriptionCallback<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, std::allocator<void> >::dispatch<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >(std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >, rclcpp::MessageInfo const&)::{lambda(auto:1&&)#1}&&, std::variant<std::function<void (sensor_msgs::msg::PointCloud2_<std::allocator<void> > const&)>, std::function<void (sensor_msgs::msg::PointCloud2_<std::allocator<void> > const&, rclcpp::MessageInfo const&)>, std::function<void (rclcpp::SerializedMessage const&)>, std::function<void (rclcpp::SerializedMessage const&, rclcpp::MessageInfo const&)>, std::function<void (std::unique_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, std::default_delete<sensor_msgs::msg::PointCloud2_<std::allocator<void> > > >)>, std::function<void (std::unique_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, std::default_delete<sensor_msgs::msg::PointCloud2_<std::allocator<void> > > >, rclcpp::MessageInfo const&)>, std::function<void (std::unique_ptr<rclcpp::SerializedMessage, std::default_delete<rclcpp::SerializedMessage> >)>, std::function<void (std::unique_ptr<rclcpp::SerializedMessage, std::default_delete<rclcpp::SerializedMessage> >, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const>, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const>)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const>, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const> const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > const> const&, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const> const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage const> const&, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >)>, std::function<void (std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >, rclcpp::MessageInfo const&)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage>)>, std::function<void (std::shared_ptr<rclcpp::SerializedMessage>, rclcpp::MessageInfo const&)> >&) () from /opt/ros/jazzy/lib/libspatio_temporal_voxel_layer_core.so
#15 0x0000ffff8afc1b00 [PAC] in ?? () from /opt/ros/jazzy/lib/libspatio_temporal_voxel_layer_core.so
#16 0x0000ffffbaa6bc38 [PAC] in rclcpp::Executor::execute_subscription(std::shared_ptr<rclcpp::SubscriptionBase>) () from /opt/ros/jazzy/lib/librclcpp.so
#17 0x0000ffffbaa6c9b4 [PAC] in rclcpp::Executor::execute_any_executable(rclcpp::AnyExecutable&) () from /opt/ros/jazzy/lib/librclcpp.so
#18 0x0000ffffbaa8164c [PAC] in rclcpp::executors::SingleThreadedExecutor::spin() () from /opt/ros/jazzy/lib/librclcpp.so
#19 0x0000ffffba601ae0 [PAC] in ?? () from /lib/aarch64-linux-gnu/libstdc++.so.6
#20 0x0000ffffba3a595c [PAC] in start_thread (arg=0x0) at ./nptl/pthread_create.c:447
#21 0x0000ffffba40b8dc in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:79

moritzboeker avatar Apr 16 '26 08:04 moritzboeker

Thank you, Alejandro. Sure, rebased it onto rolling a minute ago. Should I add a test to test_message_ filter.cpp?

moritzboeker avatar Apr 16 '26 10:04 moritzboeker

Pulls: ros2/geometry2#925 Gist: https://gist.githubusercontent.com/ahcorde/bb0cb3a7850159871cb96a37351880c5/raw/5f8b49cfc31a2d7110a5f66574fb16e7cfe2da8a/ros2.repos BUILD args: --packages-above-and-dependencies tf2_ros TEST args: --packages-above tf2_ros ROS Distro: rolling Job: ci_launcher ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18976

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

ahcorde avatar Apr 16 '26 11:04 ahcorde

Yes, I will fix the error but not sure if I can take the time before my vacation.

moritzboeker avatar Apr 16 '26 15:04 moritzboeker

I will come back to this in May after my vacation

moritzboeker avatar Apr 17 '26 14:04 moritzboeker

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • [ ] Queue this pull request

mergify[bot] avatar Jun 25 '26 15:06 mergify[bot]

Sorry for coming back to this PR so late.

Catching here avoids the exception, but the message and its expected handle have already been inserted into messages_. On continue, no callback retires that handle, so the message can remain queued indefinitely. Should this path explicitly drop the message with a transform failure reason?

Very good point! I pushed a new version in which the message is detected according to the handle and then erased.

I could add a unit test in message_filter_test.cpp covering the new catch-and-drop path in add(): a custom fake buffer class whose waitForTransform() always throws synchronously. Adding a PointStamped to a filter built on that buffer should hit EXPECT_NO_THROW, and the registered success callback should never fire for it. Downside: MessageFilter's BufferT template param must satisfy both tf2::BufferCoreInterface and tf2_ros::AsyncBufferInterface, so the fake buffer needs ~8 stub methods (most unreachable, just there to satisfy the interfaces). So this adds quite some boilerplate to the test file. Is it worth it, or rather an overkill for this fix?

Yes, I think the test is worth it. This path changes queue/failure semantics, so I’d pin it with one focused regression: no throw, success callback never fires, and the failure callback fires once with NoTransformFound. The small fake-buffer boilerplate is reasonable here.

sylvesterkaczmarek avatar Oct 06 '26 11:10 sylvesterkaczmarek

Ok good. I added a test which covers no throw and that the success callback never fires. However, asserting that the failure callback fires once is not easily possible atm, because signalFailure() called by messageDropped() only logs via RCLCPP_INFO_THROTTLE but doesn't allow to access the result other than a fragile reading of log output. And registerFailureCallback() is wrapped in #if 0. Even if we enabled this method, it still seems broken because it calls registerCallback(callback, this), wiring into the success signal and not touching signalFailure(). I saw there are also legacy tests in test_tf2 which rely on registerFailureCallback and are commented out for the above reason https://github.com/ros2/geometry2/blob/rolling/test_tf2/test/test_message_filter.cpp#L247.

The newly added test correctly logs:

[ERROR 1791290832.193808384]: waitForTransform failed: synthetic synchronous failure for test
[INFO 1791290832.193892091]: Message Filter dropping message: frame 'base' at time 1791290832.194 for reason 'did not find a valid transform, this usually happens at startup ...'

That makes sense. I would not enable or test through the currently broken failure-callback plumbing just for this PR, and I would avoid asserting logs. The focused no-throw/no-success regression is enough here; the failure-callback API can be repaired separately.

sylvesterkaczmarek avatar Oct 06 '26 13:10 sylvesterkaczmarek

Perfect, thank you Sylvester!

moritzboeker avatar Oct 06 '26 13:10 moritzboeker