# rclpy.service.ServiceException: Service '/my_service' is not available after waiting 10.0 seconds

- **ID:** `ros2/ros2-service-client-wait-timeout`
- **Domain:** ros2
- **Category:** runtime_error
- **Error Code:** `ROS2-3002`
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

The service client timed out waiting for the service to become available, typically because the service server is not running, not started, or the network/domain ID prevents discovery.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ros2:humble | active | — | — |
| ros2:iron | active | — | — |
| rclpy:4.0.0 | active | — | — |
| rclcpp:18.0.0 | active | — | — |

## Workarounds

1. **Verify the service server is running and accessible. Use: ros2 service list | grep /my_service

If not listed, start the server node: ros2 run my_package my_service_server_node

Then retry the client.** (95% success)
   ```
   Verify the service server is running and accessible. Use: ros2 service list | grep /my_service

If not listed, start the server node: ros2 run my_package my_service_server_node

Then retry the client.
   ```
2. **Add a retry loop with exponential backoff in the client code instead of a single wait. Example in Python:
import rclpy
from rclpy.node import Node
from std_srvs.srv import Empty

class MyClient(Node):
    def __init__(self):
        super().__init__('my_client')
        self.cli = self.create_client(Empty, '/my_service')
        while not self.cli.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('Service not available, retrying...')
        # Proceed with service call** (90% success)
   ```
   Add a retry loop with exponential backoff in the client code instead of a single wait. Example in Python:
import rclpy
from rclpy.node import Node
from std_srvs.srv import Empty

class MyClient(Node):
    def __init__(self):
        super().__init__('my_client')
        self.cli = self.create_client(Empty, '/my_service')
        while not self.cli.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('Service not available, retrying...')
        # Proceed with service call
   ```

## Dead Ends

- **Increasing the timeout value to 30 or 60 seconds** — The service server is not running at all; a longer timeout just delays the failure. (95% fail)
- **Restarting the client node without checking the service server status** — Restarting the client does not start the service server; the root cause is the missing server. (90% fail)
