Azure / logicapps

Azure Logic Apps labs, samples, and tools
MIT License
349 stars 291 forks source link

Logic Apps doesn't properly process some HTTP requests with Transfer-Encoding: chunked #869

Closed hajekj closed 7 months ago

hajekj commented 10 months ago

Describe the Bug

I have the following Logic App: /resource/subscriptions/63dd3a98-6ad8-47ae-ae7f-568e9b3104a8/resourcegroups/LogicAppsConsumption/providers/Microsoft.Logic/workflows/case-2307310050002056/designer which is defined as the workflow JSON sample below. The trigger URL is: https://prod-06.westeurope.logic.azure.com:443/workflows/97c8d03a704c44368ca59e64d7ea425b/triggers/manual/paths/invoke?... when sending a HTTP request to this endpoint, it resolves as Traffic Manager and further resolves as either flowfe-prod-am-rp00-app.flow-prod-am-rp00-ase.p.azurewebsites.net (ASE) or flowfe-prod-am-rp.cloudapp.net (Cloud Service) with likely a 1:5 ratio. When I send a standard HTTP POST request from ASP.NET, and the request is routed through Cloud Service, the body is outputted correctly. When the request gets routed through ASE, the body is empty.

Support in the case mentioned below identified the issue here which looks like it has been present since 2016.

  1. Why does it happen only when routed through ASE and not Cloud App?
  2. Is this ever going to be fixed? It looks like only the ASE infrastructure suffers from this, and since Cloud Services as deprecated, you are more likely to break a lot of stuff, since the defaults are to use chunked encoding with HTTP POSTs in C#.

Reference Microsoft Case: #2307310050002056

Plan Type

Consumption

Steps to Reproduce the Bug or Issue

Read the bug description. And execute this from WSL:

Wrong ASE

curl --location 'https://flowfe-prod-am-rp00-app.flow-prod-am-rp00-ase.p.azurewebsites.net/workflows/97c8d03a704c44368ca59e64d7ea425b/triggers/manual/paths/invoke?...' \
--header 'Host: prod-06.westeurope.logic.azure.com' \
--header 'Content-Type: application/json' \
--header 'Transfer-Encoding: chunked' \
--data-raw '{
    "test": true
}'

Works ASE

curl --location 'https://flowfe-prod-am-rp00-app.flow-prod-am-rp00-ase.p.azurewebsites.net/workflows/97c8d03a704c44368ca59e64d7ea425b/triggers/manual/paths/invoke?...' \
--header 'Host: prod-06.westeurope.logic.azure.com' \
--header 'Content-Type: application/json' \
--data-raw '{
    "test": true
}'

Works Cloud Service

curl --location 'https://flowfe-prod-am-rp.cloudapp.net/workflows/97c8d03a704c44368ca59e64d7ea425b/triggers/manual/paths/invoke?...' \
--header 'Host: prod-06.westeurope.logic.azure.com' \
--header 'Content-Type: application/json' \
--header 'Transfer-Encoding: chunked' \
--data-raw '{
    "test": true
}'
curl --location 'https://flowfe-prod-am-rp.cloudapp.net/workflows/97c8d03a704c44368ca59e64d7ea425b/triggers/manual/paths/invoke?...' \
--header 'Host: prod-06.westeurope.logic.azure.com' \
--header 'Content-Type: application/json' \
--data-raw '{
    "test": true
}'

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Response": {
                "inputs": {
                    "body": "@triggerBody()",
                    "statusCode": 200
                },
                "kind": "http",
                "runAfter": {},
                "type": "Response"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Screenshots or Videos

No response

Additional context

Affects also Power Automate which runs on top of Logic Apps consumption. I removed the trigger URL parameters since it failed to sync to Microsoft's DevOps, however I am happy to provide those for testing.

Partially related to https://github.com/dotnet/runtime/issues/30283 and Stack Overflow providing mitigation.

AB#25096226

github-actions[bot] commented 8 months ago

This issue is stale because it has been open for 45 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

lbueker commented 7 months ago

@hajekj Did you find a solution? Facing the same issue.

hajekj commented 7 months ago

The solution is to disable chunking on HttpClient side, which can be achieved like this:

var request = new HttpRequestMessage(HttpMethod.Post, "https://...");

// https://github.com/Azure/logicapps/issues/869
var content = JsonContent.Create(body);
await content.LoadIntoBufferAsync();

request.Content = content;
abatishchev commented 2 months ago

+1, nothing works if the request body was chunked and I didn't call LoadIntoBufferAsync().