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

Make rosbag2_transport::Player::play() run in a separate thread #1503

Merged
merged 6 commits into from
Nov 29, 2023

Conversation

roncapat
Copy link
Contributor

@roncapat roncapat commented Nov 26, 2023

This is intended to solve the issue reported in #1500.
CC: @MichaelOrlov @KenYN

This can be also beneficial introductory work for #1419. As it has been noticed, playback shall start automatically when the Player component is loaded, but this can't be done via syncronous call by the component constructor.

Current status:

  • separate thread implemented
  • all tests preliminarly adapted

Anyway, I believe that a round of refactor can be done here. For example, direclty returning an std::future from wait_for_playback_to_end(). Opinions?

@KenYN may I ask you also to do a test with this branch to confirm that the play service now returns immediately?

@roncapat roncapat requested a review from a team as a code owner November 26, 2023 13:33
@roncapat roncapat requested review from emersonknapp and james-rms and removed request for a team November 26, 2023 13:33
@roncapat roncapat force-pushed the roncagliolo/async-play branch from 6ad02e2 to 24e11e7 Compare November 26, 2023 13:34
Signed-off-by: Patrick Roncagliolo <[email protected]>
@roncapat roncapat force-pushed the roncagliolo/async-play branch from 24e11e7 to f557dc5 Compare November 26, 2023 13:42
@KenYN
Copy link

KenYN commented Nov 27, 2023

I did git checkout patch-2 && git merge roncagliolo/async-play and it appears to be operating correctly, although by no means is this a thorough test, but thank you very much for this.

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roncapat See my suggestions for review fixes in the roncapat#6 PR

- Fixed multiple race conditions in tests when
wait_for_playback_to_end() calls in a separate thread before
Player::play() method. Those race conditions would likely lead to a
false negative or flaky tests.

- Replaced player_future with wait_for_playback_to_end() to the direct
call of the player_->wait_for_playback_to_end() in the most of the
places.

Signed-off-by: Michael Orlov <[email protected]>
- Rationale: To support Clang Thread Safety Analysis
- Removed locally defined TSAUniqueLock which is a duplicate of the
rcpputils::unique_lock.
- Also removed some unused includes in player.cpp and player.hpp

Signed-off-by: Michael Orlov <[email protected]>
- Rationale: Make wait_for_playback_to_finish(..) to be optionally as
a non-blocking call

Signed-off-by: Michael Orlov <[email protected]>
@roncapat
Copy link
Contributor Author

@MichaelOrlov review branch merged :)

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MichaelOrlov
Copy link
Contributor

Gist: https://gist.githubusercontent.com/MichaelOrlov/aa32bdbe242c8c06daca683655e76bb4/raw/4be47e99df1fdad56dd18ce5f2d2c4f04ff13980/ros2.repos
BUILD args: --packages-above-and-dependencies rosbag2_transport rosbag2_tests rosbag2_py
TEST args: --packages-above rosbag2_transport rosbag2_tests rosbag2_py
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/12985

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@MichaelOrlov MichaelOrlov changed the title Make play() run in a separate thread (#1500) Make play() run in a separate thread Nov 29, 2023
@MichaelOrlov MichaelOrlov changed the title Make play() run in a separate thread Make rosbag2_transport::Player::play() run in a separate thread Nov 29, 2023
@MichaelOrlov MichaelOrlov merged commit 1a52da8 into ros2:rolling Nov 29, 2023
14 checks passed
@MichaelOrlov
Copy link
Contributor

https://github.com/Mergifyio backport iron

Copy link

mergify bot commented Nov 29, 2023

backport iron

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 29, 2023
)

* Play spawns a separate thread

Signed-off-by: Patrick Roncagliolo <[email protected]>

* Address multiple race conditions in player and some renames after review

Signed-off-by: Michael Orlov <[email protected]>

* Fixes in the rosbag2_transport tests

- Fixed multiple race conditions in tests when
wait_for_playback_to_end() calls in a separate thread before
Player::play() method. Those race conditions would likely lead to a
false negative or flaky tests.

- Replaced player_future with wait_for_playback_to_end() to the direct
call of the player_->wait_for_playback_to_end() in the most of the
places.

Signed-off-by: Michael Orlov <[email protected]>

* Rename wait_for_playback_to_end() to the wait_for_playback_to_finish()

Signed-off-by: Michael Orlov <[email protected]>

* Use rcpputils::unique_lock for RCPPUTILS TSA guarded mutexes

- Rationale: To support Clang Thread Safety Analysis
- Removed locally defined TSAUniqueLock which is a duplicate of the
rcpputils::unique_lock.
- Also removed some unused includes in player.cpp and player.hpp

Signed-off-by: Michael Orlov <[email protected]>

* Add timeout parameter to the wait_for_playback_to_finish(timeout)

- Rationale: Make wait_for_playback_to_finish(..) to be optionally as
a non-blocking call

Signed-off-by: Michael Orlov <[email protected]>

---------

Signed-off-by: Patrick Roncagliolo <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Co-authored-by: Michael Orlov <[email protected]>
(cherry picked from commit 1a52da8)

# Conflicts:
#	rosbag2_transport/src/rosbag2_transport/player.cpp
@MichaelOrlov
Copy link
Contributor

Note:
Backporting to the Iron and Humble is not possible because It will cause ABI-breaking changes.

  • it requires adding new member variables to the Player class and we don't have pimpl design for the Player class on the Iron and Humble branches.

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.

play service call doesn't return until play finished
3 participants