# Race Condition When Running Two Stretches

**URL:** <https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802>\
**Category:** Ask\
**Created:** [September 8, 2023, 1:34am UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802 "2023-09-08T01:34:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JannaLam](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/jannalam/32/539_2.png) [@JannaLam](https://forum.hello-robot.com/u/JannaLam)\
**Post date:** [September 8, 2023, 1:34am UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/1 "2023-09-08T01:34:45Z")

</div>

Hi! We are trying to send commands to two stretches at the same time so that they can turn to the object, lift the arm, and grab the item. However, when we tried this portion of the functions:

 ![Screenshot 2023-09-07 at 9.28.45 PM](https://canada1.discourse-cdn.com/flex030/uploads/hello_robot2/original/1X/ab6e03e0c37df71ea6fb0c60ff1028f4d02fe140.png)  
It shows the error “Got a result when we were already in the DONE state”. Our hypothesis is that the functions send\_goal() and wait\_for\_result() might be accessing the same variables, causing a race condition when one robot finished execution (done = True) but the other hasn’t. Is there a way to resolve this? Thank you!

---

<div class="post-metadata">

**Author:** ![bshah](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/bshah/32/55_2.png) [@bshah](https://forum.hello-robot.com/u/bshah)\
**Post date:** [September 8, 2023, 4:23am UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/2 "2023-09-08T04:23:24Z")

</div>

Hi @JannaLam, just to confirm that I understand, is it the case that you’re sending both Stretchs the same command with a single node? This might explain the error; if both Stretch received the same command, they would both report Done when they completed the command. For your use-case, would it make sense to remap each Stretch’s topics (e.g. `/stretch1/stretch_controller/follow_joint_trajectory` and `/stretch2/stretch_controller/follow_joint_trajectory`), so you can send commands to each Stretch without mixing them up.

---

<div class="post-metadata">

**Author:** ![JannaLam](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/jannalam/32/539_2.png) [@JannaLam](https://forum.hello-robot.com/u/JannaLam)\
**Post date:** [September 8, 2023, 12:58pm UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/3 "2023-09-08T12:58:31Z")

</div>

We did not directly subscribe to these topics. Instead, we use the built-in function send\_goal(), etc. If we add namespace for each of the Stretch’s trajectory topic, should we also revise the send\_goal function? Thanks!

---

<div class="post-metadata">

**Author:** ![JannaLam](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/jannalam/32/539_2.png) [@JannaLam](https://forum.hello-robot.com/u/JannaLam)\
**Post date:** [September 9, 2023, 4:06pm UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/4 "2023-09-09T16:06:50Z")

</div>

Hi, we tried adding “stretch1” manually before everywhere “/stretch\_controller/follow\_joint\_trajectory” is used on the robots, and also adding a remap in stretch\_driver.launch, but then when running our launch file there is no response and no error message, so looks like there is some sort of miscommunication - could you please provide more suggestions on this? Thanks:)

---

<div class="post-metadata">

**Author:** ![bshah](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/bshah/32/55_2.png) [@bshah](https://forum.hello-robot.com/u/bshah)\
**Post date:** [September 11, 2023, 6:56pm UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/5 "2023-09-11T18:56:25Z")

</div>

I’d recommend using the [rqt\_graph](https://wiki.ros.org/rqt_graph) tool to visualize the topics and the connections between them. You can use the ROS graph to identify which edge is missing, which should help you identify the reason for the no response error message.

---

<div class="post-metadata">

**Author:** ![JannaLam](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/jannalam/32/539_2.png) [@JannaLam](https://forum.hello-robot.com/u/JannaLam)\
**Post date:** [September 29, 2023, 7:53pm UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/6 "2023-09-29T19:53:26Z")

</div>

Just an update 🙂  
We are able to have a master node controlling several stretches at a time to have them doing several tasks (same or different) at the same time! We made some revisions in the built-in hello\_misc.py so that each robot can recognize which result should be sent to which robot, and we can also apply multi-threading rn. Thanks again for your help!

---

<div class="post-metadata">

**Author:** ![bshah](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/bshah/32/55_2.png) [@bshah](https://forum.hello-robot.com/u/bshah)\
**Post date:** [October 1, 2023, 5:01am UTC](https://forum.hello-robot.com/t/race-condition-when-running-two-stretches/802/7 "2023-10-01T05:01:21Z")

</div>

That’s great to hear @JannaLam! If you’re interested in merging your solution back upstream, let me know!
