Skip to content

[don't merge!] min reproducer for fast dds shm memory leak#2378

Closed
MichaelOrlov wants to merge 2 commits intojazzyfrom
morlov/min-reproducer-for-fast-dds-shm-leak
Closed

[don't merge!] min reproducer for fast dds shm memory leak#2378
MichaelOrlov wants to merge 2 commits intojazzyfrom
morlov/min-reproducer-for-fast-dds-shm-leak

Conversation

@MichaelOrlov
Copy link
Copy Markdown
Contributor

Description

  • This PR is a Minimal Reproducer for the issue with the memory leak reported in the Memory "leak" #2366.

It adds two small executables in rosbag2_examples_cpp:

  • byte_burst_publisher
  • byte_subscriber_probe

Files:

What they do

  • byte_burst_publisher publishes:
    • many small messages on /small_topic, or
    • large std_msgs/msg/ByteMultiArray messages on /big_topic
    • optionally creates transient /many/t* topics to mimic topic churn from the original report
  • byte_subscriber_probe is a minimal non-rosbag2 subscriber for /big_topic
    • it only subscribes
    • counts messages
    • reports the largest payload received
    • this is useful to check whether memory growth reproduces without rosbag2 in-process

Build

If example_interfaces is already available in your environment, just build rosbag2_examples_cpp.

source <your_ros_setup>/setup.bash
colcon build --packages-select rosbag2_examples_cpp

If example_interfaces is present in source but not installed in your current environment, build it first and source that prefix:

source /home/morlov/ros2_jazzy/install/setup.bash

colcon build \
  --packages-select example_interfaces \
  --base-paths /home/morlov/ros2_jazzy/src/ros2 \
  --build-base /tmp/example_interfaces_build \
  --install-base /tmp/example_interfaces_install

source /tmp/example_interfaces_install/setup.bash

colcon build \
  --packages-select rosbag2_examples_cpp \
  --base-paths /home/morlov/ros2_jazzy/src/ros2/rosbag2 \
  --build-base /tmp/rosbag2_examples_build \
  --install-base /tmp/rosbag2_examples_install

Run the minimal non-rosbag2 reproducer

Terminal 1, start the subscriber probe:

source /tmp/rosbag2_examples_install/setup.bash
source /tmp/example_interfaces_install/setup.bash

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
unset FASTDDS_BUILTIN_TRANSPORTS

ros2 run rosbag2_examples_cpp byte_subscriber_probe

Terminal 2, publish large messages in bursts:

source /tmp/rosbag2_examples_install/setup.bash
source /tmp/example_interfaces_install/setup.bash

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
unset FASTDDS_BUILTIN_TRANSPORTS

for i in 1 2 3 4 5; do
  ros2 run rosbag2_examples_cpp byte_burst_publisher --ros-args \
    -p mode:=big \
    -p big_mib:=10 \
    -p big_count:=20 \
    -p create_many_topics:=false
  sleep 2
done

In a third terminal, monitor RSS of the subscriber process:

watch -n 1 'ps -o pid,rss,cmd -C byte_subscriber_probe'

Compare RMW / transport behavior

Fast DDS with SHM enabled

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
unset FASTDDS_BUILTIN_TRANSPORTS

This is the configuration that reproduced the large RSS jump in testing.

Fast DDS with SHM disabled

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTDDS_BUILTIN_TRANSPORTS=UDPv4

This should keep RSS much flatter.

Cyclone DDS

export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
unset FASTDDS_BUILTIN_TRANSPORTS

This should also stay much flatter.

Optional rosbag2-style publisher behavior

To include transient /many/t* topic churn:

ros2 run rosbag2_examples_cpp byte_burst_publisher --ros-args \
  -p mode:=big \
  -p big_mib:=10 \
  -p big_count:=20 \
  -p create_many_topics:=true

To generate only the small-message stream:

ros2 run rosbag2_examples_cpp byte_burst_publisher --ros-args \
  -p mode:=small \
  -p small_count:=1000000

Expected result

The minimal subscriber reproducer is intended to show that:

  • large-message memory growth can be observed without rosbag2 in-process
  • the effect is much stronger with rmw_fastrtps_cpp + SHM enabled
  • the effect is much smaller or flat with:
    • rmw_fastrtps_cpp + SHM disabled
    • rmw_cyclonedds_cpp

This helps separate rosbag2 behavior from middleware receive-path behavior.

@MichaelOrlov MichaelOrlov mentioned this pull request Mar 15, 2026
@MichaelOrlov MichaelOrlov changed the base branch from rolling to jazzy March 16, 2026 01:48
@MichaelOrlov MichaelOrlov deleted the morlov/min-reproducer-for-fast-dds-shm-leak branch April 2, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants