# rclpy: 服务调用超时，等待来自/my_service的响应

- **ID:** `ros2/ros2-service-call-timeout-no-response`
- **领域:** ros2
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务服务器在超时时间内没有响应，通常是因为它正忙、被阻塞或没有正确旋转。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ROS2 Humble (rclpy 3.3.0) | active | — | — |
| ROS2 Iron (rclpy 4.0.0) | active | — | — |
| ROS2 Rolling (rclpy 5.0.0) | active | — | — |

## 解决方案

1. ```
   检查服务器节点是否在旋转：确保服务器代码中调用了rclpy.spin(node)。如果使用多线程执行器，请验证它正在运行。
   ```
2. ```
   在客户端中添加带有指数退避的重试机制：while not future.done(): time.sleep(0.1); if not rclpy.ok(): break
   ```

## 无效尝试

- **Increase the timeout duration in the client code** — The server may be completely unresponsive; a longer timeout just delays the failure. (70% 失败率)
- **Restart the client node only** — The server node needs to be restarted or checked; client restart does not fix server issues. (90% 失败率)
