Skip to content

Action Server - MultiThreadedExecutor #1598

@daBaret

Description

@daBaret

Generated by Generative AI

No response

Operating System:

Linux d-thinkpad 6.14.0-1019-oem #19-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 18 05:40:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

ROS version or commit hash:

jazzy

RMW implementation (if applicable):

rmw_fastrtps_cpp

RMW Configuration (if applicable):

No response

Client library (if applicable):

rclpy: ros-jazzy-rclpy/noble,now 7.1.9

'ros2 doctor --report' output

No response

Steps to reproduce issue

Modify the action server python example for ros2 adding the MultiThreadedExecutor and add a sleep function after succeeding

import time

from action_tutorials_interfaces.action import Fibonacci

import rclpy
from rclpy.action import ActionServer
from rclpy.node import Node
from rclpy.executors import MultiThreadedExecutor


class FibonacciActionServer(Node):

    def __init__(self):
        super().__init__('fibonacci_action_server')
        self._action_server = ActionServer(
            self,
            Fibonacci,
            'fibonacci',
            self.execute_callback)

    def execute_callback(self, goal_handle):
        self.get_logger().info('Executing goal...')

        feedback_msg = Fibonacci.Feedback()
        feedback_msg.partial_sequence = [0, 1]

        for i in range(1, goal_handle.request.order):
            feedback_msg.partial_sequence.append(
                feedback_msg.partial_sequence[i] + feedback_msg.partial_sequence[i-1])
            self.get_logger().info('Feedback: {0}'.format(feedback_msg.partial_sequence))
            goal_handle.publish_feedback(feedback_msg)
            time.sleep(1)

        time.sleep(1)
        
        result = Fibonacci.Result()
        result.sequence = feedback_msg.partial_sequence
        goal_handle.succeed(result)
        return result


def main(args=None):
    rclpy.init(args=args)
    
    executor = MultiThreadedExecutor()
    node = FibonacciActionServer()
    node.get_logger().info("FibonacciActionServer started")
    executor.add_node(node)
    executor.spin()


if __name__ == '__main__':
    main()

Expected behavior

Sending goal:
order: 2

Goal accepted with ID: 61167ef1a2604eb8b7f5ec4405368e88

Result:
sequence:

  • 0
  • 1
  • 1

Goal finished with status: SUCCEEDED

Actual behavior

The server succeeds before returning the result

Sending goal:
order: 2

Goal accepted with ID: 51d29e344cdb4f008756c4cad3c2c932

Result:
sequence: []

Goal finished with status: SUCCEEDED

Additional information

This happens only in the version 7.1.9 of rclpy. I've done the same test on 7.1.5-1noble.20251007.225057 and the bug is not present there.

Thank you for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions