ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
753 stars 911 forks source link

'while' loop creates an empty bag file for every time interval between start time and current time #2317

Open SamuelHerring opened 1 year ago

SamuelHerring commented 1 year ago

ros_comm/tools/rosbag/src/recorder.cpp has a bug that makes it vulnerable to generating lots of empty bag files if there is a time jump between "start_time_" and "t"(current time).

We are running recorder.cpp on a Jetson Nano, which takes some time after boot to get the up-to-date time. This updates the system time, creating a time jump. This can easily be 100s of days, causing the recorder.cpp node to generate 100Ks of empty bag files.

The culprit is the Recorder::checkDuration function (line 516), which slowly counts forwards from the start time to the present time in 30-second (in our case) increments, creating a bag file for each.

I'd suggest that changing the line "start_time_ += options_.max_duration;" (line 529) to be "start_time_ = t;" This would mean that this loop is only executed once on startup, and "start_time_" would get updated to the current time in one go, rather than in increments of "options_.max_duration".

As this would only execute once, I also suggest that the "while" (line 524) is replaced with a simple "if".

Many Thanks

robot-dan commented 1 year ago

Had similar issues when time-jumping during a rosbag record, would love a fix.