Skip to content

Allow configuring the daemon inactivity timeout#1240

Open
benaliabderrahmane wants to merge 1 commit into
ros2:rollingfrom
benaliabderrahmane:configurable-daemon-timeout
Open

Allow configuring the daemon inactivity timeout#1240
benaliabderrahmane wants to merge 1 commit into
ros2:rollingfrom
benaliabderrahmane:configurable-daemon-timeout

Conversation

@benaliabderrahmane

Copy link
Copy Markdown

Fixes #1239.

The daemon's inactivity timeout was hard-coded to 2 hours. We run robots for days with a large number of nodes, and once the daemon has timed out an occasional ros2 CLI call respawns a node and triggers DDS discovery, which shows up as a CPU spike. This makes the timeout configurable so a single long-lived daemon can be kept around instead.

  • ros2 daemon start --timeout N shuts the daemon down after N seconds of inactivity. The default is still 2 hours, so behavior is unchanged unless you ask for it.
  • A negative value disables the timeout, so the daemon stays up until it is explicitly stopped (same convention as helpers.wait_for).
  • spawn_daemon() gains an inactivity_timeout argument; the auto-spawn path keeps the 2 hour default.
  • Also fixes _ros2_daemon's existing --timeout: a negative value used to make the daemon exit immediately, now it disables the timeout.

This intentionally only affects daemons started explicitly; auto-spawned daemons keep the 2 hour default.

Added test/test_daemon_timeout.py covering the new argument and the short-timeout / never-timeout behavior.

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just a minor comment. i think this optional argument is nice to have, i also think that use case is well explained.

Comment thread ros2cli/test/test_daemon_timeout.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the ROS 2 CLI daemon’s inactivity shutdown behavior configurable, allowing long-lived daemons (including “never time out”) to avoid periodic respawns and DDS rediscovery spikes.

Changes:

  • Exposes an inactivity --timeout option on ros2 daemon start (default remains 2 hours; negative disables the timeout).
  • Plumbs the configured inactivity timeout through spawn_daemon() into the daemon server loop.
  • Adds tests validating the CLI argument exposure and the timeout/never-timeout behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ros2cli/test/test_daemon_timeout.py Adds new tests covering explicit daemon start inactivity timeout behavior.
ros2cli/ros2cli/verb/daemon/start.py Adds ros2 daemon start --timeout and forwards it to spawn_daemon().
ros2cli/ros2cli/node/daemon.py Extends spawn_daemon() with inactivity_timeout and passes it into the daemon server.
ros2cli/ros2cli/daemon/init.py Implements “negative timeout disables inactivity timeout” behavior and updates _ros2_daemon --timeout help text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ros2cli/ros2cli/node/daemon.py Outdated
Comment thread ros2cli/ros2cli/daemon/__init__.py
Comment thread ros2cli/test/test_daemon_timeout.py Outdated
The daemon shuts itself down after a fixed 2 hours of inactivity, after
which the next ros2 command has to respawn it. Expose this as a --timeout
option on `ros2 daemon start` (the default stays 2 hours), and let a
negative value disable the timeout so the daemon keeps running until it is
explicitly stopped.

The value is threaded through spawn_daemon() via a new inactivity_timeout
argument; the auto-spawn path keeps the 2 hour default. This also fixes
_ros2_daemon's existing --timeout, where a negative value used to make the
daemon exit immediately instead of disabling the timeout.

Signed-off-by: Abderahmane BENALI <46283596+benaliabderrahmane@users.noreply.github.com>
@benaliabderrahmane benaliabderrahmane force-pushed the configurable-daemon-timeout branch from d4aa609 to 206b0a4 Compare June 4, 2026 12:30
@benaliabderrahmane

Copy link
Copy Markdown
Author

Thanks for the review!

Pushed an update addressing everything:

  • Moved the tests into test_ros2cli_daemon.py and dropped the separate file along with the duplicated fixtures, reusing the existing rmw isolation setup.
  • Fixed the "the the" typo in the docstring (and the same one a few lines up in shutdown_daemon).
  • Changed the timeout annotation on serve() / serve_and_close() to float, since a negative value gets turned into float('inf').
  • Bumped the inactivity timeout in the shutdown test from 2s to 5s so it isn't racy on slower CI.

Kept it as a single commit since it's one logical change, happy to split it if you'd rather.

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm with green CI.

@fujitatomoya

Copy link
Copy Markdown
Collaborator

Pulls: #1240
Gist: https://gist.githubusercontent.com/fujitatomoya/be9302cd2ce538a423c908bc67759de2/raw/b4a0545a7d59f5dfa0906726ffebdac457064d5f/ros2.repos
BUILD args: --packages-above-and-dependencies ros2cli
TEST args: --packages-above ros2cli
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/19480

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

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.

ros2 daemon inactivity timeout (2 hours) isn't configurable

3 participants