Search code examples
visual-studio-codeazure-functionsvscode-debuggerazure-durable-functionsazure-functions-core-tools

Segmentation fault while debuggin a C# Azure Function in VS Code


Developing locally a bunch of Azure functions using

  • Windows 10 64-bit
  • Visual Studio Code
  • C#/.NET Core

Everything was working great. I was able to develop and debug my Azure functions locally and then deploy them to Azure. However a day ago, I upgraded from netcoreapp2.2 to netcorepp3.1. Here is my current settings.json

{
  "azureFunctions.deploySubpath": "bin/Release/netcoreapp3.1/publish",
  "azureFunctions.projectLanguage": "C#",
  "azureFunctions.projectRuntime": "~3",
  "debug.internalConsoleOptions": "neverOpen",
  "azureFunctions.preDeployTask": "publish",
  "azureFunctions.templateFilter": "Verified"
}

Now I can still start the local debug session by pressing F5. But when I attempt an http request against the localhost:7071 API address, the debugger session terminates with the following message:

...
[7/30/2020 8:21:32 PM] f4f4622abc054ed29ac69f1210a204a8: Function 'GetScorecardsByActionTargetType (Orchestrator)' completed. ContinuedAsNew: False. IsReplay: False. Output: (332 bytes). State: Completed. HubName: PolTrackTestHubV5. AppName: . SlotName: . ExtensionVersion: 2.2.2. SequenceNumber: 8.
[7/30/2020 8:21:32 PM] Executed 'GetScorecardsByActionTargetType' (Succeeded, Id=11f2a673-851e-4afb-9ed6-81f6e3eefc8d)
Stack overflow.
/d/Users/xxx/AppData/Roaming/npm/func: line 14:  2125 Segmentation fault      node "$basedir/node_modules/azure-functions-core-tools/lib/main.js" "$@"       
The terminal process "C:\Program Files\Git\bin\bash.exe '-c', 'func host start'" terminated with exit code: 139.

Any ideas as to what broke during the upgrade (I assume the upgrade is what caused it)?

EDIT:

I commented out the new function (an orchestration) I am working on. Instead I tried to run in the debugger one of the older orchestrations that used to work before the upgrade and that I have not changed. This older function is in the same local functions project as the new one.

Here is the Terminal Window transcript:

[7/31/2020 3:30:48 AM] Task hub worker started. Latency: 00:00:02.1744949. InstanceId: . Function: . HubName: PolTrackTestHubV5. AppName: . SlotName: . ExtensionVersion: 2.2.2. SequenceNumber: 1.
[7/31/2020 3:30:48 AM] Host started (2892ms)
[7/31/2020 3:30:48 AM] Job host started
Hosting environment: Production
Content root path: D:\Users\xxx\Documents\VisSources\PolTrackCosmosDbFunctions\bin\Debug\netcoreapp3.1
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[7/31/2020 3:30:53 AM] Host lock lease acquired by instance ID '000000000000000000000000B1FC0ED8'.
[7/31/2020 3:32:36 AM] Executing HTTP request: {
[7/31/2020 3:32:36 AM]   "requestId": "425ae07f-7bb8-4c54-beb7-d0c1eb43b6ba",
[7/31/2020 3:32:36 AM]   "method": "GET",
[7/31/2020 3:32:36 AM]   "uri": "/api/action-info-docs/get-one/asdfasdfasdfasdf"
[7/31/2020 3:32:36 AM] }
[7/31/2020 3:32:37 AM] Executing 'GetActionInfoDocOrchestration_HttpStart' (Reason='This function was programmatically called via the host APIs.', 
Id=c67317dd-3f7e-4eab-89ef-2d3bfe155597)
[7/31/2020 3:32:37 AM] c3879f9bdd5f4665952b319a48b81eb7: Function 'GetActionInfoDocOrchestration (Orchestrator)' scheduled. Reason: NewInstance. IsReplay: False. State: Scheduled. HubName: PolTrackTestHubV5. AppName: . SlotName: . ExtensionVersion: 2.2.2. SequenceNumber: 2.
[7/31/2020 3:32:59 AM] Started GetActionInfoDocOrchestration orchestration with ID = 'c3879f9bdd5f4665952b319a48b81eb7'.
[7/31/2020 3:32:59 AM] Executing 'GetActionInfoDocOrchestration' (Reason='', Id=7d29ec59-3cf6-467b-8cd3-a0d50d2b8eb4)
[7/31/2020 3:32:59 AM] c3879f9bdd5f4665952b319a48b81eb7: Function 'GetActionInfoDocOrchestration (Orchestrator)' started. IsReplay: False. Input: (72 bytes). State: Started. HubName: PolTrackTestHubV5. AppName: . SlotName: . ExtensionVersion: 2.2.2. SequenceNumber: 3.
[7/31/2020 3:32:59 AM] Running GetActionInfoDocOrchestration.
[7/31/2020 3:32:59 AM] c3879f9bdd5f4665952b319a48b81eb7: Function 'GetActionInfoDocOrchestration (Orchestrator)' completed. ContinuedAsNew: False. 
IsReplay: False. Output: (48 bytes). State: Completed. HubName: PolTrackTestHubV5. AppName: . SlotName: . ExtensionVersion: 2.2.2. SequenceNumber: 
4.
[7/31/2020 3:32:59 AM] Executed 'GetActionInfoDocOrchestration' (Succeeded, Id=7d29ec59-3cf6-467b-8cd3-a0d50d2b8eb4)
Stack overflow.

At this point the worker thread is paused on Stack Overflow exception. The call stack contains a large number of exceptions similar to this enter image description here

EDIT #2 Call Stack

EDIT #3

Http Trigger code (the function takes one string argument called docuemntId)

        [FunctionName(THIS_ORCHESTRATION + "_HttpStart")]
        public async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "action-info-docs/get-one/{documentId}")] HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            string documentId, ILogger log)
        {
            string instanceId = await starter.StartNewAsync(THIS_ORCHESTRATION, null, documentId);

            log.LogInformation($"Started {THIS_ORCHESTRATION} orchestration with ID = '{instanceId}'.");

            DurableOrchestrationStatus status;
            while (true)
            {
                status = await starter.GetStatusAsync(instanceId);
                if (status.RuntimeStatus == OrchestrationRuntimeStatus.Completed ||
                    status.RuntimeStatus == OrchestrationRuntimeStatus.Failed ||
                    status.RuntimeStatus == OrchestrationRuntimeStatus.Terminated)
                {
                    break;
                }
            }
            return req.CreateResponse(System.Net.HttpStatusCode.OK, status.Output);
        }

EDIT #4

As suggested below, I changed the Http trigger of the orchestration I am calling from [DurableClient] IDurableOrchestrationClient starter [DurableClient] IDurableClient starter. There are five other orchestrations in this project that I have not changed.

After the Stack Overflow message, I also get the following message after the debug session terminates: The terminal process "C:\Program Files\Git\bin\bash.exe '-c', 'func host start'" terminated with exit code: 233.

EDIT #5

I did make the change from IDurableOrchestrationClient to IDurableClient to all six of the orchestrations in my functions project. Still get the same error.


Solution

  • It turns out the problem was caused by this code in the HttpStart function of the orchestration:

                DurableOrchestrationStatus status;
                while (true)
                {
                    status = await starter.GetStatusAsync(instanceId);
                    if (status.RuntimeStatus == OrchestrationRuntimeStatus.Completed ||
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Failed ||
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Terminated)
                    {
                        break;
                    }
                }
                return req.CreateResponse(System.Net.HttpStatusCode.OK, status.Output);
    

    The Stack Overflow exception went away after I replaced the above code with

      return await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId);