Skip to content

Add server_is_available to ActionClientState#622

Draft
patrick-deschambault wants to merge 5 commits intoros2-rust:mainfrom
patrick-deschambault:main
Draft

Add server_is_available to ActionClientState#622
patrick-deschambault wants to merge 5 commits intoros2-rust:mainfrom
patrick-deschambault:main

Conversation

@patrick-deschambault
Copy link
Copy Markdown

Description

This PR adds the server_is_available method to ActionClientState.

Currently, rclrs action clients does not have a built-in mechanism to verify the availability of an action server on the network. This makes it difficult to safely send goals upon initialization without risking dropped requests.

By exposing the rcl_action_server_is_available binding, this PR enables developers to easily build reliable waiting logic.

Example Use Case

This enables the implementation of async timeout loops in user code, such as:

async fn wait_for_server(&self, timeout: std::time::Duration) -> Result<(), rclrs::RclrsError> {
    tokio::time::timeout(timeout, async {
        loop {
            if self.client.server_is_available()? {
                return Ok(());
            }
            tokio::time::sleep(std::time::Duration::from_millis(100)).await;
        }
    }).await.unwrap_or(Err(rclrs::RclrsError::Custom("Timeout".into())))
}

type: git
url: https://github.com/ros2/unique_identifier_msgs.git
version: humble
ros2/geometry2:
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.

@patrick-deschambault thanks for the PR, can you elaborate why you needed this? Could you remove it if you don't need it? Thanks.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My mistake ! Should be erased ( 3cf276e )

@esteve
Copy link
Copy Markdown
Collaborator

esteve commented Apr 11, 2026

@patrick-deschambault CI is failing because the code is not formatted properly, could you run cargo fmt and fix the warnings? Thanks

///
/// Returns an [`RclrsError`] if there is an issue communicating with the
/// underlying `rcl` C layer.
pub fn server_is_available(&self) -> Result<bool, RclrsError> {
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.

It'd be really useful to provide tests for this function, could you add them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes sure, I'll put the PR on Draft and bring it Under Review when ready. Thanks for your input !

@patrick-deschambault patrick-deschambault marked this pull request as draft April 11, 2026 22:29
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