Long running flows in Power Apps in 2024

Long running flow giving 504 Gateway Timeout error

Long running flows in Power Apps in 2024

By:

Date:

How often do you need to do something complicated in Power Apps and you use Flow to do this for you? Long running flows can cause problems.

What is a long running flow?

When this something takes longer than a minute you might run into issues. These long running flows called from Power Apps will time out after one minute. The Power Platform can handle long running flows, however when you call them from Power Apps you might have to do some additional work.

In my example app below, I can enter a number of seconds that a flow will run before responding to the app. The Request to the backend timed out message will appear after a while

Long running flows in Power Apps in 2024

On community sites, this is also a frequently asked question, but without any real good answers.

During one of my projects I recently ran into the issue where the flows would sometimes take longer than 2 minutes. Then as I tested the solution I also found that you get the same error when you close the app before the flow has finished.

Long running flows

As a test I created a flow that simply waits for 2 minutes and then I called it from a Button or a Timer in Power Apps and in both cases I received the following failure

Long Running flows PA respond
Long Running flows PA respond

The execution of template action ‘Respond_to_a_PowerApp_or_flow’ is failed: the client application timed out waiting for a response from service. This means that workflow took longer to respond than the alloted timeout value. The connection maintained between the client application and service will be closed and client application will get an HTTP status code 504 Gateway Timeout.

In my case I was able to optimise the flow a bit and the problem went away. Of course it doesn’t stop the user from closing the Power App. So you might need to add some error handling on the Respond to a PowerApp or flow action.

How to optimize your flows?

There are a number of strategies that you can follow. First of all you could speed up a flow a bit

For more information see the following posts:

Create smaller flows

Quite often flows process data. Quite often it is possible to split the overall tasks into smaller tasks and make multiple calls to flows.

Another approach could be to get a flow to run through multiple stages where each stage is processed within a switch step in a flow. You then get multiple flow runs for a single flow. See also State driven flow.

In the below example there are 3 stages that the flow is going through.

  • New
  • In Progress
  • Complete

Each of these stages take a certain part of the process.

Long running flows in Power Apps in 2024

While the flow is

Long running flows in Power Apps in 2024

Now within the Power App, the following calls to our flow will need to be made:

Set(varNextStage, "New");
Set(varNextStage, LongRunningFlow.Run( Value(TextInput1.Text),varNextStage).next_state);
Set(varNextStage, LongRunningFlow.Run( Value(TextInput1.Text),varNextStage).next_state);
Set(varNextStage, LongRunningFlow.Run( Value(TextInput1.Text),varNextStage).next_state);
Long running flows in Power Apps in 2024

Unfortunately it isn’t possible to call flows from a ForAll loop. But this is already a lot more reliable than just having one long running flow that may or may not time out.

Now one alternative could still be to use a timer in the app. This timer can be started by the click of the button and will run the code. However timers run at a set interval, which may be difficult to manage if you can’t predict the time a flow runs.

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There’s a better way — and I can show you exactly what it looks like. I’m the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I’ve been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://staging.sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://staging.sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@staging.sharepains.com

18 responses to “Long running flows in Power Apps in 2024”

  1. Heli Avatar
    Heli

    Is there any solution for this issue ? Can we add timeout time ?

    1. Pieter Veenstra Avatar

      Hi Heli,

      In general flows shouldn’t run very long. Splitting up flows or using any of the optimization steps that I have blogged about should help.

      Can you give some details on what your flow is doing.

      I will include some links to Power Automate optimization posts in this post.

  2. FlowJoe Avatar

    It’s a big problem trying to run RPA’s from a PowerApp as they’re slow too.

    1. Pieter Veenstra Avatar

      Hi Joe,

      This is one of the reasons why in general RPA isn’t a great idea. It doesn’t give you the finer control that the classic flows give you. In general using APIs rather than RPA is quicker and more reliable.

  3. wsalling Avatar

    I have a JSON that has 1000+ rows. the ForEach is taking over an hour to update excel sheet. what can be done to speed this process up and respond before timing out in powerapps waiting for response.

  4. Sascha Avatar
    Sascha

    First Peter: Thank you for all your posts (very informative). If one gets to large of arrays to GRAPH there is a HTTP timeout issue that comes up on this. Thus how would one go about best splitting the data into decent sided batches.

    1. Pieter Veenstra Avatar

      I would probably look at creating filters on the MS Graph call. Most likely i would do this by creating a custom connector that way configuring the filters will become easier.

  5. Robin Roy Avatar
    Robin Roy

    Hi Pieter,

    I received the same error, but the flow run time was only 10 seconds. Any idea what might have went wrong?

    Thank you.

    1. Pieter Veenstra Avatar

      Hi Robin,

      I think that your flow is being kicked off by your ap, however the respond back tot he app action is never run. So your flow is finishing as there are now more steps to execute, but the app hasn’t received a response back yet.

  6. akthar Avatar

    Hi Pieter ,
    There could be scenarios where the flow takes more then 3 minutes to complete e.g. if there is an on demand pull from API and ETL . Is there a way to handle long running flows ? you have only said “fix your flow to not take so long ” !! you have not told us if power app can handle long running flows

    1. Pieter Veenstra Avatar

      If you kick off the flow but don’t have a response in te flow then you can have long running flows. So then the flow could write data which is monitored by the app.

  7. akthar Avatar

    The purpose of my flow is to retrieve the data from a source , apply some transformation and deliver to a sql tables and then upon success from the flow to pull that data in to the powerapp . The actions are on demand to ensure that the latest data is retrieved . For a long running flowing i am not seeing that we can capture a success status form the flow. Your suggestion is to execute a flow and leave it running and disconnect from it.

    1. Pieter Veenstra Avatar

      Are you planning to let the user just wait staring at a busy sign in the app?

  8. akthar Avatar

    Hi Pieter ,
    I may have to at this current stage. The app is quite big and this process needs to be in line (consistent) with other already existing processes. It is an integration activity from another data sources.

    The following has an approach that I may be able to work with and test out and model to my needs:https://powerusers.microsoft.com/t5/General-Power-Automate/Respond-to-a-PowerApp-or-flow-time-limit/td-p/945549

    1. Pieter Veenstra Avatar

      Why let users wait for a long time. Just update datasource at the end of the flow. And then have the app read that datasource within a timer. Same result better UX

  9. Simone Colombo Avatar
    Simone Colombo

    User must upload an excel file with almost 150-200 lines, process take 7-10 minutes to read excel and move data inside my dataverse table… any suggestion to manage it?

    1. Pieter Veenstra Avatar

      Can you send me a message on the chat. Then we can organise a Teams call to see if we can improve that a bit.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.