Skip to content

Commit cad8d0f

Browse files
fix: index rmw_take_sequence output by the taken cursor to avoid holes and lost messages
1 parent dbf1097 commit cad8d0f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎rmw_unix_socket_cpp/src/rmw_subscription.cpp‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,23 @@ rmw_ret_t rmw_take_sequence(
370370
auto msg = std::move(sub_data->message_queue.front());
371371
sub_data->message_queue.pop_front();
372372

373+
// Write successes contiguously at the *taken cursor (not the loop counter):
374+
// a skipped failure must not leave an uninitialized hole that the consumer
375+
// would read as a valid message, nor push a later success past size==*taken.
373376
if (!rmw_uds::deserialize(msg.payload.data(), msg.payload.size(),
374-
sub_data->callbacks, message_sequence->data[i]))
377+
sub_data->callbacks, message_sequence->data[*taken]))
375378
{
379+
// Dropped datagram already popped from the queue — log like the other
380+
// take paths so the operator sees a truncated/mismatched payload. Throttle.
381+
RMW_UDS_LOG_ERROR_THROTTLE(
382+
1000,
383+
"rmw_take_sequence: CDR deserialization failed on topic '%s' (payload=%zu bytes) "
384+
"— likely truncated or type mismatch with publisher",
385+
sub_data->topic_name.c_str(), msg.payload.size());
376386
continue;
377387
}
378388

379-
auto & info = message_info_sequence->data[i];
389+
auto & info = message_info_sequence->data[*taken];
380390
info.source_timestamp = msg.header.source_timestamp_ns;
381391
info.received_timestamp = msg.received_timestamp_ns;
382392
info.publication_sequence_number = static_cast<uint64_t>(msg.header.sequence_number);

0 commit comments

Comments
 (0)