Skip to content

Commit 9435bee

Browse files
author
Mauro Passerino
committed
Always publish inter-process on TRANSIENT_LOCAL pubs (#152)
1 parent c2acb19 commit 9435bee

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

rclcpp/include/rclcpp/publisher.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ class Publisher : public PublisherBase
351351
bool inter_process_publish_needed =
352352
get_subscription_count() > get_intra_process_subscription_count();
353353

354-
if (inter_process_publish_needed) {
354+
// If the publisher is configured with transient local durability, we must publish
355+
// inter-process. This ensures that the RMW stores the messages for late joiner subscriptions.
356+
// This has the consequence of subscriptions experiencing the double-delivery issue
357+
// mentioned in https://github.com/ros2/rclcpp/issues/1750
358+
if (inter_process_publish_needed || buffer_) {
355359
auto ros_msg_ptr = std::make_shared<ROSMessageType>();
356360
// TODO(clalancette): This is unnecessarily doing an additional conversion
357361
// that may have already been done in do_intra_process_publish_and_return_shared().
@@ -363,11 +367,6 @@ class Publisher : public PublisherBase
363367
buffer_->add_shared(ros_msg_ptr);
364368
}
365369
} else {
366-
if (buffer_) {
367-
auto ros_msg_ptr = std::make_shared<ROSMessageType>();
368-
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*msg, *ros_msg_ptr);
369-
buffer_->add_shared(ros_msg_ptr);
370-
}
371370
this->do_intra_process_publish(std::move(msg));
372371
}
373372
}

0 commit comments

Comments
 (0)