Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ros2 bag record and play does occasionally not properly closing when pressing Ctrl+C #1079

Closed
FranzAlbers opened this issue Sep 5, 2022 · 2 comments · Fixed by #1081
Closed
Assignees
Labels
bug Something isn't working

Comments

@FranzAlbers
Copy link

FranzAlbers commented Sep 5, 2022

Description

When closing a recording, occasionally, the ros2 bag is apparently not closed correctly, which makes a reindex of the bag necessary.
This happens for both the sqlite3 and the mcap plugins. Usually, this is no big issue and takes only a few seconds, but reindexing these mcap files seems to be not possible for now (which is another issue).
For our setup (recording point clouds, images, and GNSS data), this issue occurs in most cases.

Expected Behavior

The recording should stop and write the remaining messages from the cache to the bag. A metadata.yaml file should be created.

...
[INFO] [1662381739.854492546] [rosbag2_recorder]: Subscribed to topic '/sensing/gnss/fixed'
[INFO] [1662381739.856257118] [rosbag2_recorder]: Subscribed to topic '/sensing/gnss/pose'
[INFO] [1662381746.062154306] [rclcpp]: signal_handler(signum=2)
[INFO] [1662381746.159286989] [rosbag2_cpp]: Writing remaining messages from cache to the bag. It may take a while

Actual Behavior

ros2 bag record is stuck at signal_handler(signum=2). The remaining messages are not written to the bag and killing the recording process or closing the terminal is required. No metadata.yaml file is created.

...
[INFO] [1662381748.073734704] [rosbag2_recorder]: Subscribed to topic '/sensing/gnss/fixed'
[INFO] [1662381748.076060419] [rosbag2_recorder]: Subscribed to topic '/sensing/gnss/pose'
[INFO] [1662381754.862466740] [rclcpp]: signal_handler(signum=2)

To Reproduce

** Steps to reproduce the behavior, e.g.

  1. Start a recording with ros2 bag record -a. Actually, this issue also occurs when no other node is running and only the recording is started.
  2. Stop recording with Ctrl+C.
  3. It might need a few tries, but for me, in roughly half of the cases the recording is not stopped correctly, and killing the process is required.

System (please complete the following information)

  • OS: Ubuntu Jammy
  • ROS 2 Distro: Humble
  • Version: 0.15.2-1jammy.20220729 (apt release)

RCA (Root Cause Analysis)

  1. Rosbag2 player and recorder not finishing correctly because it's waiting for Enter key to be pressed after CTRL+C. If press Enter key after CTRL+C rosbag2 finishes correctly.
  2. Rosbag2 expecting Enter key because we catching SIGINT signal in keyboard handler and returning input from unbuffered to the canonical mode
  3. which is imply to block next read from std input until Enter key will be pressed. Which normal and default behavior when we returning to the console.
  4. However we are not returning to the console right after SIGINT but rather trying to dismiss it on upper level and call rclcpp::shutdown() for instance here to invalidate context and force finishing current application.
  5. We basically have infinite loop with check
while (rclcpp::ok() {

inside executor_>spin(); call
6. We are exiting from infinite loop and going in to rosbag2 destructor when we triggering rclcpp::shutdown()
7. Hangout with wait for Enter key happening when we are trying to destruct keyboard_handler_ instance and waiting to join main keyboard handler thread in it's own destructor.

 if (key_handler_thread_.joinable()) {
    key_handler_thread_.join();
  }
  1. Main keyboard_handler thread hangout for joining because it got blocked on read_fn system function call which became as a blocking call and waiting for Enter key to be pressed after we changed input to the canonical mode in signal handler.

Proposed solution

  • Do not use signal handler in Keyboard handler class since we are going to ignore it and correctly finish our application on upper level. There are available specific parameter in keyboard_handler constructor to avoid handling SIGINT.
  • Trigger internal exit variable to true from signal handler in keyboard handler to avoid getting stuck on next read function after changing the canonical input mode.
@FranzAlbers FranzAlbers added the bug Something isn't working label Sep 5, 2022
@FranzAlbers FranzAlbers changed the title ros2 bag record does not properly close recoring ros2 bag record does not properly close recording Sep 5, 2022
@FranzAlbers FranzAlbers changed the title ros2 bag record does not properly close recording ros2 bag record does occasionally not properly close recording Sep 5, 2022
@MichaelOrlov
Copy link
Contributor

@FranzAlbers It seems that I know what is causing this issue and I have a fix for it.
To double check can you please try to press Enter key when you see that rosbag2 reorder hangout after Ctrl+C?

Sorry for inconvenience. I am expecting that pressing Enter should work as workaround until we will fix this issue with a proper way.

@MichaelOrlov MichaelOrlov self-assigned this Sep 7, 2022
@FranzAlbers
Copy link
Author

@MichaelOrlov, thanks for your help and for the hint!

Pressing enter indeed works as a workaround.

@MichaelOrlov MichaelOrlov changed the title ros2 bag record does occasionally not properly close recording ros2 bag record and play does occasionally not properly closing when pressing Ctrl+C Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants