5
votes

I have a logic app that uses For_each to iterate through email attachments and saves them to an Azure Files container.

Depending on some conditions, I want the attachment stored with a different name or at a different path, but the default concurrency of for_each is concerning; I have path and file name variables set at top level and I'm setting them in the loop as conditions are met.

Is there a way to be sure that these variables will hold the value I'm setting in that iteration without setting concurrency to 1?

It seems like it's working correctly with default concurrency, but I'm going to set concurrency to 1 until I'm sure about whether or not these iterations can interfere with each other in terms of setting variables.

2

2 Answers

6
votes

If you are changing the variable value inside the for-each loop (and potentially also consuming it in the same loop), you should set concurrency to 1 to ensure the loop runs in a sequential fashion to avoid racing conditions.

1
votes

Since variables can be declared only on top level, this will not be used on some scenarios without settings concurrency to 1. Consider we have JSON with this schema:

`[
   {
    [JSON Object]
   }
 ]` 

and needs to iterate each inner to get value and increase the counter and based on counter we have some action. In this condition, we require local variable instead of global variables.