Ensure latched messages are updated on every split #2261
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This fixes an issue with #1850 - latched messages from the same publisher are not updated in the
Recorder
.Steps to Reproduce
rosrun rosbag record -a --repeat-latched --duration 10 --split
rostopic echo -b <last_split>.bag chatter
Expected behavior
The first message in the last split is the value of the latched topic when the split was started (e.g.,
data: "18"
).Actual behavior
The first message in the last split is the value of the latched topic when the
rosbag record
was run (e.g.,data: "0"
).Implications
This behavior causes issues when recording latched topics that are not often updated. If the
rosbag record
is a long-running process, the latched topic values in some splits may be several hours old (if the publisher does not send an update within the split time frame).Cause
Latched messages are stored as a
std::map<std::pair<std::string, std::string>, OutgoingMessage>
, where the key is a pair of strings (topic and publisher name) and the value is the latched message.When updating the
latched_msgs_
map, thestd::map::insert()
function is used. This behaves as expected when the key does not yet exist in the map. However, if the key exists, the old value is not updated:This effectively means that the first value (latched message) that was inserted into the map will persist across the whole
rosbag record
.Solution
Check for insertion success and assign value manually if required (see commit).