Skip to content

Commit aab59a0

Browse files
author
Mauro Passerino
committed
Implement no-op on IPC subscription
1 parent 02c2ef1 commit aab59a0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>
9191

9292
if (!has_data_()) {
9393
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Calling dequeue on empty intra-process buffer");
94-
throw std::runtime_error("Calling dequeue on empty intra-process buffer");
94+
// This situation can happen on the EventsExecutor if we have more events in the queue
95+
// than messages in the history cache (set by the qos_policies.depth of the subscription)
96+
// For example if we set depth=1 and we get 2 messages really fast (so no time for processing),
97+
// we could end up with 2 events in the queue but only 1 msg is actually stored on the buffer.
98+
// In this case we return an empty buffer.
99+
return BufferT();
95100
}
96101

97102
auto request = std::move(ring_buffer_[read_index_]);

rclcpp/include/rclcpp/experimental/subscription_intra_process.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase
129129

130130
if (any_callback_.use_take_shared_method()) {
131131
shared_msg = buffer_->consume_shared();
132+
if(!shared_msg) {
133+
return nullptr;
134+
}
132135
} else {
133136
unique_msg = buffer_->consume_unique();
137+
if(!unique_msg) {
138+
return nullptr;
139+
}
134140
}
135141
return std::static_pointer_cast<void>(
136142
std::make_shared<std::pair<ConstMessageSharedPtr, MessageUniquePtr>>(
@@ -185,7 +191,8 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase
185191
execute_impl(std::shared_ptr<void> & data)
186192
{
187193
if (!data) {
188-
throw std::runtime_error("'data' is empty");
194+
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Subscription intra-process: 'data' is empty");
195+
return;
189196
}
190197

191198
rmw_message_info_t msg_info;

0 commit comments

Comments
 (0)