Skip to content

ROS2ServiceAPI.call_service timeout handling #514

Open
@maciejmajek

Description

@maciejmajek

Is your feature request related to a problem? Please describe.
Currently, the call_service method of the ROS2ServiceAPI does not respect the timeout parameter during the actual service call. The timeout is only applied during service discovery.

def call_service(
self,
service_name: str,
service_type: str,
request: Any,
timeout_sec: float = 1.0,
) -> Any:
"""
Call a ROS2 service.
Args:
service_name: Name of the service to call
service_type: ROS2 service type as string
request: Request message content
Returns:
The response message
"""
srv_msg, srv_cls = build_ros2_service_request(service_type, request)
service_client = self.node.create_client(srv_cls, service_name) # type: ignore
client_ready = service_client.wait_for_service(timeout_sec=timeout_sec)
if not client_ready:
raise ValueError(
f"Service {service_name} not ready within {timeout_sec} seconds. "
"Try increasing the timeout or check if the service is running."
)
return service_client.call(srv_msg)

Describe the solution you'd like
The timeout should apply to both the service client initialization and the service call phases. We should measure the time taken by the first phase and apply the remaining timeout to the service call.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestgood first issueGood for newcomerspriority/majorImportant work that comes next after all critical and blocking tasks are completed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions