Recently I noticed that some of my flows end up with many running flows.
Types of flows
There are a few different types of flows
- Manual cloud flows
- Scheduled cloud flows
- Automated cloud flows
When I looked into the issues of many flow runs, I found that they were always scheduled flows.
And whenever I would open the flows there would be an apply to each that was stuck.
The difficult thing is that when you open up the apply to each , you will not find out what is actually happening.
How can we debug this?
3 steps to debugging multiple running flows
I’m going for the following approach:
- Stop the flow
- Find clues and fix the flow
- Restart the flow
To stop the flow I first go to the flow and select the turn off option.
This will stop any new instances starting up.
You could now cancel all the flow instances that are running. This can be a really boring job, but it might have to be done at some point. However this is not the right moment, as I want to see where the flows are failing/hanging or timing out.
In the All runs, you will find the Running flows but also some failing or maybe successful flows.
In my case I have some failing flows. When I look at my failing flow I found a delay action failing.
Gosh, what is this about? If we can’t even wait properly then what can we do.
The error that goes with this failure says:
The provided ‘Wait’ action ‘interval’ value ‘1’ ‘Second’ is not supported for the ‘Consumption’ SKU. The value must be between ‘5’ seconds and ’30’ day(s).
Ok, so I’ve got a trial that has expired and now I’m only allowed to wait for 5 – 30 seconds. The reason for he delay was to reduce the pressure on the SharePoint connector a bit. So in this case waiting for 5 seconds probably isn’t too bad.
But this doesn’t explain why the flows are suddenly never finishing or does it?
Well, you might have noticed recently all sorts of warnings in flows that tell you when there are too many failures or too many actions run by your flows.
Have you noticed that in the apply to each steps, if any action fails, that the apply to each simply continues? In my example above one flow run would generate 465 errors. On a scheduled flows that will quite quickly result in many errors.
Looking at the analytics of the flow you can quite quickly notice that there is something wrong!
When you get too many errors, apply to each steps seem to go into a never ending pause state.
So what should we do?
- avoid errors inside large apply to each steps.
- protect your flow from running multiple instances (unless it is a requirement for this to happen)
- avoid apply to each steps, where possible
- buy a premium licence 😉 as it avoids issues like mine
Now the next step is to cancel the running flows and restart my flow.
So how do we protect our flow?
Protect a flow and stop many running flows issues
To stop the issues of many running flows you could create a SharePoint list. Call this list locks or something like that and create one item in this list.
At the start of the flow read the item and check the value of the item. If it is locked then don’t run the following steps. You can do this using a condition step.
Then within the code that you want to run set the item to locked. And at the end of your flow write to the lock item and set it to unlocked.
Then finally you might want to send yourself an email when the flow is trying to start while the flow is already running.
This way of protecting your flow might not fix the issue, but it does avoid you having to cancel 100s of flows running.