Skip to content

[mavros_node-3] terminate called after throwing an instance of 'std::future_error' --- what(): std::future_error: Promise already satisfied #2159

@Lexciese

Description

@Lexciese
...
[mavros_node-3] [INFO] [1774445147.463922507] [mavros.sys]: FCU: EKF3 IMU0 MAG0 in-flight yaw alignment complete                                                                                                    
[mavros_node-3] [INFO] [1774445147.464008288] [mavros.sys]: FCU: EKF3 IMU0 MAG0 in-flight yaw alignment complete                                                                                                    
[mavros_node-3] [INFO] [1774445147.464226900] [mavros.sys]: FCU: EKF3 IMU1 MAG0 in-flight yaw alignment complete                                                                                                    
[mavros_node-3] [INFO] [1774445147.464279880] [mavros.sys]: FCU: EKF3 IMU1 MAG0 in-flight yaw alignment complete                                                                                                    
[mavros_node-3] terminate called after throwing an instance of 'std::future_error'                                                                                                                                  
[mavros_node-3]   what():  std::future_error: Promise already satisfied 
[ERROR] [mavros_node-3]: process has died [pid 100825, exit code -6, cmd '/opt/ros/jazzy/lib/mavros/mavros_node --ro
s-args --params-file /tmp/launch_params_zwtkj3gi']

System Specification:

  • Ubuntu 24.04
  • ROS2 Jazzy
  • MAVLINK version: 2025.12.12
  • MAVROS version: 2.14.0
...
...
class PassGate(Node):
    def __init__(self):
        self.arm_client = self.create_client(CommandBool, "/mavros/cmd/arming")
        self.mode_client = self.create_client(SetMode, "/mavros/set_mode")
    def set_arm(self, arm):    
        arm_req = CommandBool.Request()
        arm_req.value = arm
        future = self.arm_client.call_async(arm_req)
        rclpy.spin_until_future_complete(self, future, timeout_sec=5.0)
        if future.result() is not None:
            response = future.result()
            if response.success:
                self.get_logger().info(f'Successfully set arm to: {arm}')
                return True
            else:
                self.get_logger().error(f'Failed to set arm to {arm}')
                return False
    
    def set_mode(self, mode):
        mode_req = SetMode.Request()
        mode_req.custom_mode = mode
        future = self.mode_client.call_async(mode_req)
        rclpy.spin_until_future_complete(self, future, timeout_sec=5.0)
        if future.result() is not None:
            response = future.result()
            if response.mode_sent:
                self.get_logger().info(f'Successfully set mode to {mode}')
                return True
            else:
                self.get_logger().error(f'Failed to set mode to {mode}')
                return False
    def initialize(self):
        self.wait_for_service()
        self.set_arm(arm=True)
        self.set_mode(mode="ALT_HOLD")
        self.set_target_depth()
        self.get_logger().info("Initialization process completed")
def main():
    rclpy.init()
    node = PassGate()
    try:
        node.initialize()
        rclpy.spin(node)
    except KeyboardInterrupt:
        node.set_mode(mode="MANUAL")
        node.set_arm(arm=False)
    except Exception as e:
        node.get_logger().error(str(e))
    finally:
        node.destroy_node()
        rclpy.shutdown()

The error is reproducable when we do service calls to the mavros service in a short period of time. The code above is a snippet of my codes that produce the error when i close the program, then start again, close again, then start again. It's not certain when the error arise, it might be after starting the program 3rd time or 4th time or even the 1st time running the program.
My assumption is because of deadlock or race condition but i don't know whether its on my code side or mavros side.
What could be the cause?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions