Skip to content

Make context initialization and destruction more robust #150

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

Merged
merged 1 commit into from
May 10, 2022
Merged

Conversation

nnmm
Copy link
Contributor

@nnmm nnmm commented May 2, 2022

Currently, when you run e.g. ros2 run rclrs_examples minimal_publisher --ros-args -r __node:=my/node, which is an invalid node name, you'll get a message

>>> [rcutils|error_handling.c:108] rcutils_set_error_state()
This error state is being overwritten:

  'Couldn't parse remap rule: '-r __node:=my/node'. Error: Expected lexeme type 1, got 19 at index 10, at /tmp/binarydeb/ros-galactic-rcl-3.1.2/src/rcl/lexer_lookahead.c:238, at /tmp/binarydeb/ros-galactic-rcl-3.1.2/src/rcl/arguments.c:371'

with this new error message:

  'context is zero-initialized, at /tmp/binarydeb/ros-galactic-rcl-3.1.2/src/rcl/init.c:238'

rcutils_reset_error() should be called after error handling to avoid this.
<<<

This is fixed by checking that the context is indeed valid before calling rcl_shutdown() and rcl_context_fini() on it, because rcl_init() leaves the context in an invalid/zero-initialized state when it returns an error. (This is a separate issue from not resetting the error state, which we'll also do soon.)

Furthermore, the Context::new method had an unnecessary dance where the rcl_context is put in a mutex and taken out again.

I also made a tiny change so that the error code is converted to a Result right after the call, in anticipation of rcl_init_options_fini(&mut init_options).ok()? possibly overwriting the error state.

@nnmm nnmm requested review from esteve and jhdcs May 2, 2022 22:11
@nnmm nnmm merged commit ed5cc98 into master May 10, 2022
@nnmm nnmm deleted the context_fixes branch May 10, 2022 15:05
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.

2 participants