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

[timer] Fix malfunction when reset cancelled timer #1013

Closed
wants to merge 1 commit into from

Conversation

DongheeYe
Copy link
Contributor

Signed-off-by: Donghee Ye donghee.ye@samsung.com

Related to #1012

To reset wait_set after reset a cancelled timer, there is needed node handle or context handle. When constructing a timer, there are context handle parameter. To trigger guard condition to reset wait_set, save context handle in constructor and trigger when reset timer.

Signed-off-by: Donghee Ye <donghee.ye@samsung.com>
@ivanpauno
Copy link
Member

@DongheeYe Thanks for opening the PR.
There seems to be a bunch of issues here:

  • Methods of the Timer class should be thread safe, and they don't seem to be.
  • Timers should trigger a guard condition when being reset/cancelled, but that should be done in rcl and not here. Probably, here and here. This same guard condition should be triggered. I'm not sure about if should be triggered when it's cancelled/reset or both.

Copy link
Member

@ivanpauno ivanpauno left a comment

Choose a reason for hiding this comment

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

See above comment #1013 (comment).

@DongheeYe
Copy link
Contributor Author

@ivanpauno Thank to comments. I'd considered to use the rcl timer guard condition, either. (here). However, I thought, the purpose of current rcl timer guard condition is to wake up of waitset when waiting timer is expired. In this case, cancelled timer guard condition is not added to the node waitset rcl_wait. So, additional guard condition is needed to wake up node waitset to add timer waitset again like. I will try to make a rcl patch that add additional guard condition to rcl timer and trigger when rcl_timer_reset.

@ivanpauno
Copy link
Member

In this case, cancelled timer guard condition is not added to the node waitset rcl_wait

I think you can change the logic to make sure is always added, instead of adding a new guard condition.

@wjwwood
Copy link
Member

wjwwood commented Mar 10, 2020

Interrupting all wait set associated with the context is overkill. It should only interrupt the wait set/executor of which the timer is associated. Pub/sub accomplish this by being lazily removed when the executor notices that the publisher or subscription have gone out of scope (it stores them as weak pointers), but they don't have a "reset" like function.

I think the best thing to do would be to get the node's node_base_interface and trigger the guard condition there, like NodeTimers::add_timer() does:

if (rcl_trigger_guard_condition(node_base_->get_notify_guard_condition()) != RCL_RET_OK) {
throw std::runtime_error(
std::string("Failed to notify wait set on timer creation: ") +
rmw_get_error_string().str);
}

You could add a method to the NodeTimersInterface that does this and call it from NodeTimers::add_timer() as well as TimerBase::reset().

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

See my other comment for how it should change.

@ivanpauno
Copy link
Member

Closed in favor of ros2/rcl#589 (I added the reviewers here by error, the intention was to add them to the rcl PR).

@ivanpauno ivanpauno closed this Mar 11, 2020
@ivanpauno
Copy link
Member

Methods of the Timer class should be thread safe, and they don't seem to be.

This comment is still valid. rcl functions aren't thread safe (they aren't intended to be), and rclcpp should provide thread safety on top of that. It would be good to add a mutex (a recursive mutex sounds suitable) to protect access to timer_handle_ member of Timer class.

Can you open a PR proposing that?

DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
* Increase test timeout and decrease msgs sent

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>

* Add debug instrumentation for `test_play_services`

- Increased service_call_timeout_ up to 3 seconds.
- Split `toggle_paused` on two separate tests `is_paused` and
`toggle_paused`
- Add output of the function name and line number in case of failure.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Restore msgs_to_publish

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>

* Fix for windows build

Add redefinition for __PRETTY_FUNCTION__ to __FUNCSIG__ if it is not
defined and not gcc compiler.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

Co-authored-by: Michael Orlov <michael.orlov@apex.ai>
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.

3 participants