Skip to content

Commit

Permalink
Timeout if service server not available within server_timeout_time (#905
Browse files Browse the repository at this point in the history
)
  • Loading branch information
michael-cmt authored Jan 31, 2024
1 parent 4d1437c commit 48a1c62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rosbridge_library/src/rosbridge_library/internal/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def call_service(
service_type = service_names_and_types.get(service)
if service_type is None:
raise InvalidServiceException(service)

# service_type is a tuple of types at this point; only one type is supported.
if len(service_type) > 1:
node_handle.get_logger().warning(f"More than one service type detected: {service_type}")
Expand All @@ -139,7 +140,10 @@ def call_service(
client = node_handle.create_client(
service_class, service, callback_group=ReentrantCallbackGroup()
)
client.wait_for_service(server_timeout_time)

if not client.wait_for_service(server_timeout_time):
node_handle.destroy_client(client)
raise InvalidServiceException(service)

future = client.call_async(inst)
while rclpy.ok() and not future.done():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_call_advertised_service(self):
loop_iterations = 0
while self.received_message is None:
rclpy.spin_once(self.node, timeout_sec=0.1)
time.sleep(0.5)
time.sleep(0.1)
loop_iterations += 1
if loop_iterations > 3:
self.fail("Timed out waiting for service call message.")
Expand Down

0 comments on commit 48a1c62

Please sign in to comment.