ros2 / ros2/rclcpp

API footgun: shared_ptr to timer, ambiguous reset

Open
#3,140 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

more-information-needed
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Generated by Generative AI

No response

Operating System:

Linux JCAPC214 6.8.0-107-generic #107-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 13 19:51:50 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

ROS version or commit hash:

humble, rolling

RMW implementation (if applicable):

No response

RMW Configuration (if applicable):

No response

Client library (if applicable):

rclcpp

'ros2 doctor --report' output

No response

Steps to reproduce issue
rclcpp::TimerBase::SharedPtr timer =
  node->create_wall_timer(1s,  {
    RCLCPP_INFO(rclcpp::get_logger("test"), "tick");
  });

// Intended: restart the timer
timer->reset();

// Accidental change during refactor:
timer.reset();  // Timer is destroyed instead
Expected behavior

Likely requires a refactor to the api to make the reset_timer explicit and not collide with the pointer

Actual behavior

Your pointer is reset and needs to be reconstructed

Additional information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the rclcpp::TimerBase::SharedPtr usage with create_wall_timer and the competing timer->reset() and timer.reset() calls shown in the reproduction. Determine whether an explicit timer-restart API is appropriate, then define the expected behavior and add coverage for restarting versus destroying the timer.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.