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 sure timer is fini'd before clock #553

Merged
merged 2 commits into from
Sep 8, 2018
Merged

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Sep 7, 2018

This PR makes sure timers are finalized before clocks. Since a timer uses a clock, the clock must be valid longer than the timer.

I suspect this will fix the windows test failures in ros2/rcl#286. That PR adds a time jump callback to the clock in rcl_timer_init(), and removes it in rcl_timer_fini(). If the clock is finalized before the timer then the attempt to remove the jump callback results in trying to access an rcl_clock_t after it has been freed.

TimerBase already has a shared pointer to Clock for this purpose, but this is insufficient. TimerBase::get_timer_handle() returns an std::shared_ptr<rcl_timer_t> with a deleter that calls rcl_timer_fini(). This handle can live longer than TimerBase in an executor's memory strategy. Specifically AllocatorMemoryStrategy keeps a list of std::shared_ptr<rcl_timer_t>. If the NodeClock and TimerBase are destroyed before an Executor then the clock is finalized before the timer handle which may result in a crash.

CI

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

blocks ros2/rcl#286

@sloretz sloretz added the in review Waiting for review (Kanban column) label Sep 7, 2018
@sloretz sloretz self-assigned this Sep 7, 2018
@@ -27,7 +27,7 @@ TimerBase::TimerBase(rclcpp::Clock::SharedPtr clock, std::chrono::nanoseconds pe
clock_ = clock;

timer_handle_ = std::shared_ptr<rcl_timer_t>(
new rcl_timer_t, [ = ](rcl_timer_t * timer)
new rcl_timer_t, [ = ](rcl_timer_t * timer) mutable
Copy link
Member

Choose a reason for hiding this comment

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

TIL about mutable with lambda's.

@sloretz sloretz merged commit b1af280 into master Sep 8, 2018
@sloretz sloretz deleted the clock_fini_after_timer branch September 8, 2018 00:28
@sloretz sloretz removed the in review Waiting for review (Kanban column) label Sep 8, 2018
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.

None yet

3 participants