Skip to content

Warn when deprecated/removed env vars are set (ROS_LOCALHOST_ONLY)#1314

Open
aki1770-del wants to merge 1 commit intoros2:rollingfrom
aki1770-del:fix/warn-deprecated-env-vars-1241
Open

Warn when deprecated/removed env vars are set (ROS_LOCALHOST_ONLY)#1314
aki1770-del wants to merge 1 commit intoros2:rollingfrom
aki1770-del:fix/warn-deprecated-env-vars-1241

Conversation

@aki1770-del
Copy link
Copy Markdown

Closes #1241.

Summary

When a user's environment still contains ROS_LOCALHOST_ONLY or LOCALHOST_ONLY — variables that were removed from rcl — the node starts silently mis-configured with no diagnostic output. This PR makes rcl_get_automatic_discovery_range() emit a RCUTILS_LOG_WARN_NAMED diagnostic for each removed variable that is present, so users receive actionable feedback.

Changes

  • rcl/src/rcl/discovery_options.c — check for ROS_LOCALHOST_ONLY and LOCALHOST_ONLY at the start of rcl_get_automatic_discovery_range(); emit RCUTILS_LOG_WARN_NAMED with migration guidance if either is set. The new canonical variable (ROS_AUTOMATIC_DISCOVERY_RANGE) is read and respected as before.
  • rcl/test/rcl/test_discovery_options.cpp — new test test_deprecated_env_vars_ignored verifying that setting either deprecated variable does not alter the discovery range returned when ROS_AUTOMATIC_DISCOVERY_RANGE is canonical.

Existing Behavior Audit (OPS-RULE-016)

File Location Env var Status
rcl/src/rcl/discovery_options.c rcl_get_automatic_discovery_range() line 52 ROS_AUTOMATIC_DISCOVERY_RANGE Current canonical var — unchanged
rcl/src/rcl/discovery_options.c rcl_get_discovery_static_peers() line 120 ROS_STATIC_PEERS Current canonical var — unchanged
rcl/src/rcl/domain_id.c rcl_get_default_domain_id() line 38 ROS_DOMAIN_ID Current canonical var — no deprecated alias found
rcl/src/rcl/discovery_options.c (new) ROS_LOCALHOST_ONLY, LOCALHOST_ONLY Removed — now detected and warned

rcutils/env.h (rcutils_get_env) and rcutils/logging_macros.h (RCUTILS_LOG_WARN_NAMED) are already included in discovery_options.c. No new dependencies added.

Scope Classification (OPS-RULE-017)

(a) Bug fix — the issue describes silent mis-configuration: a developer setting a removed env var receives no feedback. This is a targeted addition of detection logic at the existing env-reading call site.

Prior Art (OPS-RULE-018)

  1. Issue Always check/reject all deprecated/removed env variable #1241 — "Always check/reject all deprecated/removed env variable" — this PR is the direct fix.
  2. PR remove unnecessary test_with_localhost_only. #1238 — "remove unnecessary test_with_localhost_only" (merged 2025-05-14) — confirms LOCALHOST_ONLY was already removed; the test was deleted without adding a deprecation warning, which is precisely the gap this PR fills.
  3. PR Keep domain id if ROS_DOMAIN_ID is invalid. #689 — "Keep domain id if ROS_DOMAIN_ID is invalid" (merged 2020-06-22) — establishes that env var validation/error-handling in rcl is a known concern; env var edge cases have been fixed at domain_id.c before.
  4. init.c lines 186–193 (rolling) — existing RCUTILS_LOG_WARN_NAMED call for ROS_STATIC_PEERS / ROS_AUTOMATIC_DISCOVERY_RANGE=OFF conflict — this is the model for the warning pattern used here.

This change is consistent with the existing pattern of RCUTILS_LOG_WARN_NAMED in init.c for misconfigured env var combinations.

Test Evidence (OPS-RULE-011)

New test TEST(TestDiscoveryInfo, test_deprecated_env_vars_ignored) in rcl/test/rcl/test_discovery_options.cpp:

  • Sets ROS_LOCALHOST_ONLY=1, calls rcl_get_automatic_discovery_range, asserts RCL_RET_OK and RMW_AUTOMATIC_DISCOVERY_RANGE_SUBNET (from the canonical var, not the deprecated one).
  • Sets LOCALHOST_ONLY=1, same assertions.
  • Uses OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT to clean up env vars.

AI-assisted — authored with Claude, reviewed by Komada.

Closes ros2#1241.

When a user sets the removed 'ROS_LOCALHOST_ONLY' or 'LOCALHOST_ONLY'
environment variable, rcl_get_automatic_discovery_range() now emits a
RCUTILS_LOG_WARN_NAMED diagnostic explaining that the variable has been
removed and providing the canonical replacement. Previously the variable
was silently ignored, leaving the node mis-configured with no feedback.

Co-Authored-By: Claude and aki1770-del <aki1770@gmail.com>
Signed-off-by: Akihiko Komada <aki1770@gmail.com>
@aki1770-del aki1770-del force-pushed the fix/warn-deprecated-env-vars-1241 branch from 84488c3 to 4c4f478 Compare April 12, 2026 02:49
Copy link
Copy Markdown
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

to be honest, this AI generated code looks really bad quality though.

AI-assisted — authored with Claude, reviewed by Komada.

what model are you using? and can you explain about who/what Komada is?

RMW_AUTOMATIC_DISCOVERY_RANGE_ ## x

rcl_ret_t
rcl_get_automatic_discovery_range(rmw_discovery_options_t * discovery_options)
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.

this could be called multiple times, in that case printing warning everytime would be strange?
before that, i think having this check in the function is semantic wrong. this function's job is to read an env var and return a discovery range. Stuffing deprecation warnings for unrelated env vars into it looks weird for me...

"The value of 'ROS_LOCALHOST_ONLY' will be ignored.");
}
deprecated_val = NULL;
if (NULL == rcutils_get_env("LOCALHOST_ONLY", &deprecated_val) &&
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.

when have we had this environment variable? that is not what i recall...

// users who still have them in their environment receive actionable feedback.
{
const char * deprecated_val = NULL;
if (NULL == rcutils_get_env("ROS_LOCALHOST_ONLY", &deprecated_val) &&
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.

error return from rcutils_get_env is silently ignored.

EXPECT_EQ(RCL_RET_OK, rmw_discovery_options_fini(&discovery_options_var));
}

// Regression test for https://github.com/ros2/rcl/issues/1241:
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.

this test doesn't verify the warning is actually emitted. doesn't assert that a warning was actually logged.

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.

Always check/reject all deprecated/removed env variable

2 participants