Azure / Azure/logicapps

For Each (Loop) Concurrency Control Default Behaviour Causing Issues in Execution !! Request to Turn On Concurrency Control and Set it to 1 by Default !!

Open
#1,486 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
ABAP
Stars
424
Forks
320
Avg merge
14h 41m
Merged PRs (30d)
1

Description

### Severity

P2 - High (Major functionality broken)

### Describe the Bug with repro steps

Defect or Issue:
When we add a For Each (Loop) and if it contains a Set Variable within the Loop, then the Variable value of one run within the loop is getting associated with another parallel run value.

Cause:
Since the Concurrency Control is turned off by default in a 'For Each' loop, the variable values are getting messed up for parallel runs.

Resolution:
It is better to turn on the Concurrency Control and ensure the degree of parallelism to 1 for a 'For Each' loop by default. If the developer forgets to turn on the Concurrency Control and reduce the degree of parallelism to 1, then it causes huge problems in the values within the loops getting cross referenced.

Steps

1. Create a Consumption Logic App
2. Initialize a variable
3. Add a For Each Loop
4. Set the Variable value inside the For Each loop by assigning a dynamic value present within the items of the For Each loop.
5. Check the values of the variables for each loop.
6. The Values will be messed up.

Variable value set in the first execution of the loop: **a1BNz000008ywsXMAQ**

Image

Referenced Variable value in the first loop execution: **a1BNz0000090EH9MAM** **[This is incorrect]**

Image

Variable value set in the second execution of the Loop: a1BNz0000090EH9MAM

Image

Referenced Variable value in the second loop execution: a1BNz0000090EH9MAM

Image

### What type of Logic App Is this happening in?

Consumption (Portal)

### Are you experiencing a regression?

_No response_

### Which operating system are you using?

Windows

### Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

### Workflow JSON

```json
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"triggers": {
"Receive_HeyCentric_Payment_Confirmation": {
"type": "Request",
"kind": "Http",
"inputs": {
"method": "POST",
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"chargeId": {
"type": "string"
},
"paymentIntentId": {
"type": "string"
},
"subscriptionId": {},
"externalIdentifier": {
"type": "string"
},
"receiptNumber": {
"type": "string"
},
"lodgementArea": {
"type": "string"
},
"currency": {
"type": "string"
},
"timestamp": {
"type": "string"
},
"lineItems": {
"type": "array",
"items": {
"type": "object",
"properties": {
"revenueCode": {
"type": "string"
},
"amount": {
"type": "integer"
},
"paymentReference": {
"type": "string"
}
},
"required": [
"revenueCode",
"amount",
"paymentReference"
]
}
}
}
}
}
}
}
}
},
"actions": {
"Process_Payment_Confirmation": {
"actions": {
"For_Each_Line_Item": {
"foreach": "@triggerBody()?['data']?['lineItems']",
"actions": {
"Check_if_Revenue_Code_is_of_FPN_and_Amount_in_GBP_is_Greater_than_0": {
"actions": {
"Check_if_Process_Record_Exists_And_Status_is_Not_Marked_Completed": {
"actions": {
"Check_if_Payment_is_Succeeded": {
"actions": {
"Update_Process_Record": {
"runAfter": {
"Create_Financial_Record_for_the_Process_Record": [
"Succeeded"
]
},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "patch",
"body": {
"arcusregserv__Status__c": "Completed",
"arcusregserv__Penalty_Paid_Date__c": "@convertTimeZone(triggerBody()?['data']?['timestamp'],'UTC','GMT Standard Time','yyyy-MM-ddTHH:mm:ssZ')"
},
"path": "/v3/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('arcusregserv__RS_Activity__c'))}/items/@{encodeURIComponent(encodeURIComponent(variables('SF_Process_ID')))}"
}
},
"Create_Financial_Record_for_the_Process_Record": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "post",
"body": {
"RecordTypeId": "@parameters('FR_Record_Type_ID')",
"arcshared__Amount__c": "@items('For_Each_Line_Item')?['amount']",
"arcshared__Date_Paid__c": "@convertTimeZone(triggerBody()?['data']?['timestamp'],'UTC','GMT Standard Time','yyyy-MM-ddTHH:mm:ssZ')",
"arcshared__External_Reference__c": "@triggerBody()?['data']?['receiptNumber']",
"arcshared__Fund_Code__c": "@items('For_Each_Line_Item')?['revenueCode']",
"arcshared__Parent_Id__c": "@body('Fetch_Id_and_Status_from_Salesforce_Process_using_Process_Name')?['records']?[0]?['Id']",
"arcshared__Status__c": "Completed"
},
"path": "/v2/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('arcshared__Financial_Transaction__c'))}/items"
}
}
},
"else": {
"actions": {}
},
"expression": {
"and": [
{
"equals": [
"@toLower(triggerBody()?['type'])",
"payment.succeeded"
]
}
]
},
"type": "If"
}
},
"runAfter": {
"Check_if_Payment_Reference_is_Financial_Record_Id": [
"Succeeded"
]
},
"else": {
"actions": {}
},
"expression": {
"and": [
{
"not": {
"equals": [
"@variables('SF_Process_ID')",
""
]
}
},
{
"or": [
{
"not": {
"equals": [
"@variables('SF_Process_Status')",
"Completed"
]
}
},
{
"not": {
"equals": [
"@variables('SF_Process_Status')",
""
]
}
}
]
}
]
},
"type": "If"
},
"Check_if_Payment_Reference_is_Financial_Record_Id": {
"actions": {
"Fetch_Id_and_Status_from_Salesforce_Process_using_Financial_Record_Id": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "post",
"body": {
"query": "SELECT arcusregserv__Related_Process__r.Id, arcusregserv__Related_Process__r.arcusregserv__Status__c FROM arcshared__Financial_Transaction__c WHERE Id = '@{items('For_Each_Line_Item')?['paymentReference']}'"
},
"path": "/soql/executesoqlquery"
}
},
"Set_Process_Id_using_Financial_Record_Id": {
"runAfter": {
"Fetch_Id_and_Status_from_Salesforce_Process_using_Financial_Record_Id": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "SF_Process_ID",
"value": "@body('Fetch_Id_and_Status_from_Salesforce_Process_using_Financial_Record_Id')?['records']?[0]?['arcusregserv__Related_Process__r']?['Id']"
}
},
"Set_Process_Status_using_Financial_Record_Id": {
"runAfter": {
"Set_Process_Id_using_Financial_Record_Id": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "SF_Process_Status",
"value": "@body('Fetch_Id_and_Status_from_Salesforce_Process_using_Financial_Record_Id')?['records']?[0]?['arcusregserv__Related_Process__r']?['arcusregserv__Status__c']"
}
}
},
"else": {
"actions": {
"Fetch_Id_and_Status_from_Salesforce_Process_using_Process_Name": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['salesforce']['connectionId']"
}
},
"method": "post",
"body": {
"query": "SELECT Id, arcusregserv__Status__c FROM arcusregserv__RS_Activity__c WHERE name= '@{items('For_Each_Line_Item')?['paymentReference']}' OR arcusregserv__Section__c= '@{items('For_Each_Line_Item')?['paymentReference']}'"
},
"path": "/soql/executesoqlquery"
}
},
"Set_Process_Id_using_Process_Name": {
"runAfter": {
"Fetch_Id_and_Status_from_Salesforce_Process_using_Process_Name": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "SF_Process_ID",
"value": "@body('Fetch_Id_and_Status_from_Salesforce_Process_using_Process_Name')?['records']?[0]?['Id']"
}
},
"Set_Process_Status_using_Process_Name": {
"runAfter": {
"Set_Process_Id_using_Process_Name": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "SF_Process_Status",
"value": "@body('Fetch_Id_and_Status_from_Salesforce_Process_using_Process_Name')?['records']?[0]?['arcusregserv__Status__c']"
}
}
}
},
"expression": {
"and": [
{
"equals": [
"@substring(items('For_Each_Line_Item')?['paymentReference'],0,3)",
"@parameters('SF_FinancialRecordPrefix')"
]
}
]
},
"type": "If"
}
},
"else": {
"actions": {}
},
"expression": {
"and": [
{
"or": [
{
"equals": [
"@items('For_Each_Line_Item')?['revenueCode']",
"WCWS004"
]
},
{
"equals": [
"@items('For_Each_Line_Item')?['revenueCode']",
"WCWS009"
]
},
{
"equals": [
"@items('For_Each_Line_Item')?['revenueCode']",
"WCWS010"
]
},
{
"equals": [
"@items('For_Each_Line_Item')?['revenueCode']",
"WCWS003"
]
},
{
"equals": [
"@items('For_Each_Line_Item')?['revenueCode']",
"WCWS012"
]
}
]
},
{
"and": [
{
"greater": [
"@items('For_Each_Line_Item')?['amount']",
0
]
},
{
"equals": [
"@triggerBody()?['data']?['currency']",
"GBP"
]
}
]
}
]
},
"type": "If"
}
},
"type": "Foreach",
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
}
}
},
"runAfter": {
"Initialize_SF_Process_Status": [
"Succeeded"
]
},
"type": "Scope"
},
"Response": {
"runAfter": {
"Process_Payment_Confirmation": [
"Succeeded"
]
},
"type": "Response",
"kind": "Http",
"inputs": {
"statusCode": 200,
"body": "OK"
}
},
"Initialize_SF_Process_ID": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "SF_Process_ID",
"type": "string",
"value": "@{null}"
}
]
}
},
"Initialize_SF_Process_Status": {
"runAfter": {
"Initialize_SF_Process_ID": [
"Succeeded"
]
},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "SF_Process_Status",
"type": "string",
"value": "@{null}"
}
]
}
}
},
"outputs": {},
"parameters": {
"FR_Record_Type_ID": {
"defaultValue": "0128d000000Y93EAAS",
"type": "String"
},
"SF_FinancialRecordPrefix": {
"defaultValue": "a05",
"type": "String"
},
"$connections": {
"type": "Object",
"defaultValue": {}
}
}
},
"parameters": {
"$connections": {
"type": "Object",
"value": {
"salesforce": {
"id": "/subscriptions/6a4aa4e1-b4ef-4ce0-94b8-5b9db96d6087/providers/Microsoft.Web/locations/uksouth/managedApis/salesforce",
"connectionId": "/subscriptions/6a4aa4e1-b4ef-4ce0-94b8-5b9db96d6087/resourceGroups/wcc-prd-scf-rg/providers/Microsoft.Web/connections/salesforce",
"connectionName": "salesforce"
}
}
}
}
}
```

### Screenshots or Videos

_No response_

### Environment

- Chrome Browser - Version 141.0.7390.77 (Official Build) (64-bit)
- Using Azure Portal

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the issue in a Consumption Logic App using the provided workflow JSON: initialize a variable, add a For Each loop, and set the variable from each item. Verify the loop's concurrency behavior and compare the recorded values for each execution. Done means the default behavior prevents values from being cross-referenced between parallel loop runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.