Engin Mustafa
Engin Mustafa

Reputation: 1

Local Azure Function startup uses wrong Azurite service address

I am trying to run an Azure Function(.NET 6, HTTP Trigger) using Visual Studio 22 locally that uses Blob Storage. Azurite is installed and starting up automatically as service dependency in VS. I am operating under Windows 10.

Stream.DataLakeTransaction: azurite.cmd --location "\AppData\Local\.vstools\azurite" --debug "AppData\Local\.vstools\azurite\debug.log" --skipApiVersionCheck
{ProjectName}: Azurite Blob service is starting at http://127.0.0.1:10000
{ProjectName}: Azurite Blob service is successfully listening at http://127.0.0.1:10000
{ProjectName}: Azurite Queue service is starting at http://127.0.0.1:10001
{ProjectName}: Azurite Queue service is successfully listening at http://127.0.0.1:10001
{ProjectName}: Azurite Table service is starting at http://127.0.0.1:10002
I{ProjectName}: Azurite Table service is successfully listening at http://127.0.0.1:10002

On my local.settings.json file, I have the following configuration, "AzureWebJobsStorage": "UseDevelopmentStorage=true", which should resolve to the default Azurite addresses, like port 10000 for Blob service for instance. But what happens is, for some reason, the function is trying to access it at localhost:5016/ upon startup and fails because the service is not running on that port. I wonder where that port comes from, shouldn't that configuration resolve to the default address and make a connection with the running Azurite instance?

Other settings I have on local.settings.json include these(db connection strings disregarded):

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "FUNCTIONS_EXTENSION_VERSION": "~4",
  }
}

Here are the complete logs of running the function, it fails with an exception stating that it couldn't read from the Blob Storage Secret Repository.

FUNCTIONS_INPROC_NET8_ENABLED app setting is not enabled in local.settings.json
Selected inproc6 host.
Starting child process for inproc6 model host.
C:\Program Files\Microsoft\Azure Functions Core Tools\in-proc6\func.exe present
Started child process with ID: 19196
                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %
Azure Functions Core Tools
Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c5326276aae6b8a7d41ccbdeb6aa (64-bit)
Function Runtime Version: 4.35.4.23179
Found {ProjectName.csproj}. Using for user secrets file configuration.
[2024-12-03T18:00:30.447Z] Building host: version spec: ~4, startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '16eac4bd-8933-4a55-8ff5-c044ff92701f'
[2024-12-03T18:00:30.461Z] Reading host configuration file '..\bin\output\host.json'
[2024-12-03T18:00:30.465Z] Host configuration file read:
[2024-12-03T18:00:30.466Z] {
[2024-12-03T18:00:30.469Z]   "version": "2.0",
[2024-12-03T18:00:30.471Z]   "logging": {
[2024-12-03T18:00:30.472Z]     "applicationInsights": {
[2024-12-03T18:00:30.474Z]       "samplingSettings": {
[2024-12-03T18:00:30.476Z]         "isEnabled": true,
[2024-12-03T18:00:30.476Z]         "excludedTypes": "Request"
[2024-12-03T18:00:30.477Z]       }
[2024-12-03T18:00:30.477Z]     }
[2024-12-03T18:00:30.478Z]   }
[2024-12-03T18:00:30.478Z] }
[2024-12-03T18:00:30.500Z] Extension Bundle not loaded. Loading extensions from ..\bin\output\bin. BundleConfigured: False, PrecompiledFunctionApp: False, LegacyBundle: False, DotnetIsolatedApp: False, isLogicApp: False
[2024-12-03T18:00:30.503Z] Script Startup resetting load context with base path: '..bin\output\bin'.
[2024-12-03T18:00:30.511Z] Loading startup extension 'Startup'
[2024-12-03T18:00:30.593Z] Loaded extension 'Startup' (1.0.0.0)
[2024-12-03T18:00:30.612Z] Loading startup extension 'DurableTask'
[2024-12-03T18:00:30.615Z] Loaded extension 'DurableTask' (2.0.0.0)
[2024-12-03T18:00:30.617Z] Loading startup extension 'EventGrid'
[2024-12-03T18:00:30.621Z] Loaded extension 'EventGrid' (2.1.0.0)
[2024-12-03T18:00:30.648Z] Reading host configuration file '..\bin\output\host.json'
[2024-12-03T18:00:30.650Z] Host configuration file read:
[2024-12-03T18:00:30.651Z] {
[2024-12-03T18:00:30.654Z]   "version": "2.0",
[2024-12-03T18:00:30.657Z]   "logging": {
[2024-12-03T18:00:30.658Z]     "applicationInsights": {
[2024-12-03T18:00:30.660Z]       "samplingSettings": {
[2024-12-03T18:00:30.661Z]         "isEnabled": true,
[2024-12-03T18:00:30.663Z]         "excludedTypes": "Request"
[2024-12-03T18:00:30.665Z]       }
[2024-12-03T18:00:30.666Z]     }
[2024-12-03T18:00:30.667Z]   }
[2024-12-03T18:00:30.669Z] }
[2024-12-03T18:00:31.403Z] Using the default storage provider: AzureStorage.
[2024-12-03T18:00:32.665Z] Initializing Warmup Extension.
[2024-12-03T18:00:32.678Z] Resolved secret storage provider BlobStorageSecretsRepository
[2024-12-03T18:01:20.598Z] There was an error performing a read operation on the Blob Storage Secret Repository.
[2024-12-03T18:01:20.601Z] Azure.Core: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Http: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Sockets: No connection could be made because the target machine actively refused it.
[2024-12-03T18:01:20.671Z] A host error has occurred during startup operation '16eac4bd-8933-4a55-8ff5-c044ff92701f'.
[2024-12-03T18:01:20.674Z] Azure.Core: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Http: No connection could be made because the target machine actively refused it. (localhost:5016). System.Net.Sockets: No connection could be made because the target machine actively refused it.

I tried reinstalling VS, Azurite, Azure Core tools, running the function through command line to isolate VS, restarts, cleaning Azurite Temp data - none of that helped so far. Setting "AzureWebJobsSecretStorageType": "files" on local.settings.json makes the function accessible(it doesn't fail during startup), but a trigger ends up with the same error as above in the end.

Any help would be appreciated, I can provide more info if needed. Thanks in advance.

EDIT: Here is the function code:


using Domain.Models.Shared.Transactions;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Stream.Transaction
{
    public class TransactionOrchestrationClient
    {
        [FunctionName(nameof(TransactionOrchestrationClient))]
        public async Task TransactionTrigger(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger logger)
        {
            try
            {
                var data = await req.Content.ReadAsAsync<Transaction>();
                var instanceId = await starter.StartNewAsync(nameof(TransactionOrchestrator), data);
                logger.LogInformation($"Started orchestration with ID = '{instanceId}'.");
                starter.CreateHttpManagementPayload(instanceId);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error occurred while executing {nameof(TransactionOrchestrationClient)}");
            }
        }
    }
}

Upvotes: 0

Views: 111

Answers (1)

Pravallika KV
Pravallika KV

Reputation: 8400

By default, the storage emulator services run on the below ports as mentioned in MSDOC.

Note the ProcessID of the tasks using the PORT 10000, 10001,10002 using the command:

netstat -p tcp -ano | findstr :<PORT>

Example:

netstat -p tcp -ano | findstr :10001

TCP    127.0.0.1:10001        0.0.0.0:0              LISTENING       10376(process_id)

Kill the task using the service's PID with the command:

taskkill /PID <process_id> /F

Example:

taskkill /PID 10376 /F
SUCCESS: The process with PID 10376 has been terminated.

Restart Azurite, refer MSDOC for the command:

"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Azure Storage Emulator\azurite.exe"

Note: If your system is under company's proxy, you might get the same error. To resolve this, change the network connection and test the function again.

I have tested the function with your code:

public static class Function1
{
    [FunctionName("Function1")]
    public static async Task<List<string>> RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var outputs = new List<string>();
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo"));
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Seattle"));
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "London"));
        return outputs;
    }

    [FunctionName(nameof(SayHello))]
    public static string SayHello([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation("Saying hello to {name}.", name);
        return $"Hello {name}!";
    }

    [FunctionName("Function1_HttpStart")]
    public static async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        string instanceId = await starter.StartNewAsync("Function1", null);

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

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

Output:

Azure Functions Core Tools
Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c53262XX7d41ccbdeb6aa (64-bit)
Function Runtime Version: 4.35.4.23179

[2024-12-04T08:31:56.803Z] Found C:\Users\uname\Source\Repos\FunctionApp\FunctionApp.csproj. Using for user secrets file configuration.
Functions:

        Function1_HttpStart: [GET,POST] http://localhost:7068/api/Function1_HttpStart

        Function1: orchestrationTrigger

        SayHello: activityTrigger

For detailed output, run func with --verbose flag.
[2024-12-04T08:32:05.712Z] Executing 'Function1_HttpStart' (Reason='This function was programmatically called via the host APIs.', Id=7ecac355-6aff-440f-95f1-ab992ecf5ac2)
[2024-12-04T08:32:09.010Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-12-04T08:32:09.103Z] Started orchestration with ID = '35d89e5d87c44b8bb47dc3d93ffcf767'.
[2024-12-04T08:32:09.150Z] Executed 'Function1_HttpStart' (Succeeded, Id=7ecac355-6aff-440f-95f1-ab992ecf5ac2, Duration=3466ms)
[2024-12-04T08:32:09.284Z] Executing 'Function1' (Reason='(null)', Id=cd0324d9-63ce-4a88-9f81-304763b959d7)
[2024-12-04T08:32:09.334Z] Executed 'Function1' (Succeeded, Id=cd0324d9-63ce-4a88-9f81-304763b959d7, Duration=55ms)
[2024-12-04T08:32:09.419Z] Executing 'SayHello' (Reason='(null)', Id=262653d8-a03e-4723-a43d-5242140090a7)
[2024-12-04T08:32:09.424Z] Saying hello to Tokyo.
[2024-12-04T08:32:09.427Z] Executed 'SayHello' (Succeeded, Id=262653d8-a03e-4723-a43d-5242140090a7, Duration=11ms)
[2024-12-04T08:32:09.528Z] Executing 'Function1' (Reason='(null)', Id=c07866a3-f609-4a08-9c1f-07fdda972c56)
[2024-12-04T08:32:09.536Z] Executed 'Function1' (Succeeded, Id=c07866a3-f609-4a08-9c1f-07fdda972c56, Duration=8ms)
[2024-12-04T08:32:09.574Z] Executing 'SayHello' (Reason='(null)', Id=3695b57e-a07d-4428-95d4-397954b84fd9)
[2024-12-04T08:32:09.578Z] Saying hello to Seattle.
[2024-12-04T08:32:09.580Z] Executed 'SayHello' (Succeeded, Id=3695b57e-a07d-4428-95d4-397954b84fd9, Duration=7ms)
[2024-12-04T08:32:09.619Z] Executing 'Function1' (Reason='(null)', Id=433593d2-f089-4b65-8397-801cd1f0f910)
[2024-12-04T08:32:09.624Z] Executed 'Function1' (Succeeded, Id=433593d2-f089-4b65-8397-801cd1f0f910, Duration=5ms)
[2024-12-04T08:32:09.651Z] Executing 'SayHello' (Reason='(null)', Id=a517ad04-532a-4bf6-8245-3a3598b014ba)
[2024-12-04T08:32:09.655Z] Saying hello to London.
[2024-12-04T08:32:09.657Z] Executed 'SayHello' (Succeeded, Id=a517ad04-532a-4bf6-8245-3a3598b014ba, Duration=6ms)
[2024-12-04T08:32:09.685Z] Executing 'Function1' (Reason='(null)', Id=ef0c8206-0633-46b1-aefa-a9661d18a59d)
[2024-12-04T08:32:09.695Z] Executed 'Function1' (Succeeded, Id=ef0c8206-0633-46b1-aefa-a9661d18a59d, Duration=9ms)

Upvotes: 0

Related Questions