Let's consider the following scenario
- The Logic App receives a request that contains an array
- It iterates with a parallel for-each loop through the array
- A filename with a @guid() is generated
- A result array of these file names is composed
- The Logic App returns that array as a response
The variable is initialized at a global level and not within the for-each loop. This means that multiple parallel for-each executions are working against the same instance of the global variable. Depending on race conditions, this might lead to incorrect functioning of your Logic App.
The issue can be simply resolved by using the Compose action instead of variables. The Compose is instantiated within each individual for-each iteration, so there's no possibility that other for-each iterations interfere.
Don't use the Set Variable action within a non-sequential for-each loop! Use the Compose action, instead!