Skip to content

GAP for a partially reassembled sample leaves a released change in an unkeyed DataReader's instance; take() then loops forever #6567

Open

Description

@mfinean

Is there an already existing issue for this?

  • I have searched the existing issues

Expected behavior

When a reliable DataReader receives a GAP covering a sample whose fragments it is still
reassembling, the partial sample is discarded and later take() calls keep working.

Current behavior

On an unkeyed topic the partial sample stays referenced from the DataReaderHistory instance
after it has been released, and the next take() never returns. It holds the reader mutex, so
every receive thread that dispatches to that reader blocks behind it, and the whole participant
stops receiving.

Sequence, from uprobes on 2.14.6 (ros-jazzy-fastrtps):

  1. The first DATA_FRAG of a large sample arrives. StatefulReader::processDataFragMsg creates the
    change and change_received → DataReaderHistory::received_change. For an unkeyed topic
    compute_key_for_change_fn_ returns true even though the change is not fully assembled, so it is
    added to the history and to the instance's cache_changes (add_to_instance).
  2. The writer (KEEP_LAST 1) replaces that sample before the reader acks it and sends a GAP.
  3. StatefulReader::processGapMsg finds the partial change with findCacheInFragmentedProcess and
    removes it with mp_history->History::remove_change_nts(ret_iterator) ("we call the History
    version to avoid callbacks"). That bypasses DataReaderHistory::remove_change_nts, which is
    what removes it from the instance, and releases the change (payload length 0).
  4. ReadTakeCommand::add_instance reaches the released change, deserialization fails
    (NotEnoughMemoryException in read_encapsulation), and it calls
    history_.remove_change_sub(change, it). find_change_nts cannot find it, so it returns false
    without advancing it, and the loop continues on the same element forever.

Stack of the releasing call (receive thread):

CacheChangePool::release_cache(CacheChange_t*)
History::remove_change_nts(const_iterator, bool)
StatefulReader::processGapMsg(...)
MessageReceiver::proc_Submsg_Gap(...)
MessageReceiver::processCDRMsg(...)
ReceiverResource::OnDataReceived(...)
SharedMemChannelResource ... receive thread

Spinning thread: DataReaderImpl::take → read_or_take → TypeSupport::deserialize (throws) →
DataReaderHistory::remove_change_sub(change, it) returns false, repeatedly (millions of times/s).

The same code is in 2.14.x HEAD (StatefulReader.cpp, processGapMsg) and in master
(process_gap_msg's remove_fn).

Steps to reproduce

  • Writer: reliable, KEEP_LAST 1, unkeyed type, samples far above the fragment size (we hit it with
    a 29.5 MB sensor_msgs/PointCloud2 at ~20 Hz over SHM; any size > 64 KB fragments).
  • Reader: reliable, KEEP_LAST 1, in another process, slow enough to fall one sample behind
    (CPU-starved).
  • Within seconds to minutes a GAP lands mid-reassembly and the reader's process freezes.
    A best-effort reader is unaffected (it never processes GAPs).

Fast DDS version/commit

2.14.6 (ROS 2 Jazzy binaries); code unchanged in 2.14.x HEAD and master.

Platform/Architecture

Ubuntu Noble 24.04 amd64

Transport layer

Shared Memory Transport (SHM) (also UDPv4 in the participant)

Additional context

Suggested fixes: remove the change through DataReaderHistory (so the instance is cleaned) in the
GAP path, or do not put partially assembled changes into an unkeyed instance until
completed_change, as is already done for keyed topics. Separately, ReadTakeCommand::add_instance
could advance it when remove_change_sub fails, so a corrupted entry costs one sample instead of
the participant.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions