# Safely Handle Synchronous Task Failures (avoid re-run)

**URL:** <https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484>\
**Category:** Uncategorized\
**Created:** [May 1, 2024, 3:37pm UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484 "2024-05-01T15:37:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanwar](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tanwar](https://forum.flowable.org/u/Tanwar)\
**Post date:** [May 1, 2024, 3:37pm UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484/1 "2024-05-01T15:37:28Z")

</div>

Hi,

I’m aware of the async job and how it moves to dead letter.

My questions is regarding going ahead with synchronous tasks and if something fails, then how to make sure we don’t re-execute the service tasks which were executed succesfully.

For example:

wait state 1 → make API call (service task1) → send email (service task 2) → wait state 2

When my flow moves from wait state 1 followed by executing service task 1 successfully but fails sending email i.e. service task 2. Then my flow will come back to wait state 1.

Now if I re-trigger the flow from wait state 1 , how can I avoid executing service task1 and just going ahead with task 2 which failed earlier.

is there something I can do?

Please let me know.

@joram May I pls have some feedback on this pls. sorry, if tagging ins’t allowed

---

<div class="post-metadata">

**Author:** ![Tanwar](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tanwar](https://forum.flowable.org/u/Tanwar)\
**Post date:** [May 2, 2024, 9:40pm UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484/2 "2024-05-02T21:40:15Z")

</div>

@filiphr May I pls get done feedback on this pls.

---

<div class="post-metadata">

**Author:** ![Tanwar](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tanwar](https://forum.flowable.org/u/Tanwar)\
**Post date:** [May 16, 2024, 9:46am UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484/3 "2024-05-16T09:46:43Z")

</div>

Any feedback on this pls.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [June 12, 2024, 11:41am UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484/4 "2024-06-12T11:41:59Z")

</div>

Hey @Tanwar,

You can’t handle this when doing it synchronously. When there is a failure, Flowable is going to rollback the transaction.

You have one of the following options:

## Use Boundary Error Event

On your service tasks configure the handled exceptions and use BPMN Boundary Error to navigate if an exception happens

## Use Async (Leave)

When using async or async leave service tasks then the transaction boundaries change. e.g. if your email task is async, then if it fails the transaction will only rollback prior to the execution of the email. If it is async leave then if the next task fails the transaction will rollback just after sending the email (it won’t retry the email).

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![Tanwar](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tanwar](https://forum.flowable.org/u/Tanwar)\
**Post date:** [June 12, 2024, 12:09pm UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484/5 "2024-06-12T12:09:36Z")

</div>

it’s fine if it’ll rollback.  
I’m talking about the scenario where I wake up the workflow from the waiting state it rolled back to.

I do not want to re execute the task1 as it was succesful earlier and go to service task 2.

I guess I can do this by setting a task variable at the end of the task execution indicating it’s done.  
So, when we try to re-execute it, we’ll check that variable was true and skip the task.

what do you think.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [June 18, 2024, 6:54pm UTC](https://forum.flowable.org/t/safely-handle-synchronous-task-failures-avoid-re-run/11484/6 "2024-06-18T18:54:08Z")

</div>

> [@Tanwar](#):
>
> I guess I can do this by setting a task variable at the end of the task execution indicating it’s done.  
> So, when we try to re-execute it, we’ll check that variable was true and skip the task.
> 
> what do you think.

That’s more or less what I meant with the “Use Boundary Error Event” section. Keep in mind that just setting the variable isn’t enough, as if the transaction rolls back, the variable update will not be persisted in the DB.
