Host is shutting down - Azure Functions

Obaid UrRehman 166 Reputation points


I am testing an azure function using the standard template Azure Blogb Trigger. The aim is to read CSV files from a blob using the managed identity. The role assignments are fine.

Here is the local.settings.json:

      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "python",
        "AZURE_STORAGE_HOST": "", 
        "AZURE_STORAGE_ACCOUNT": "mystorage",

And here is the function.json

  "scriptFile": "",
  "bindings": [
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "folderInBlob/{blobName}",
      "connection": "AzureWebJobsStorage"

and the init file:

import logging

import azure.functions as func

def main(myblob: func.InputStream):"Python blob trigger function processed blob \n"
                 f"Name: {}\n"
                 f"Blob Size: {myblob.length} bytes")

Its a pretty standard code that comes with init.

The error I receive is:

[2022-04-09T16:29:50.335Z] An unhandled exception has occurred. Host is shutting down.
[2022-04-09T16:29:50.335Z] Microsoft.Azure.Storage.Common: Connection refused ( System.Net.Http: Connection refused ( System.Net.Sockets: Connection refused.
[2022-04-09T16:29:53.075Z] The listener for function 'Functions.blobCheck' was unable to start.
[2022-04-09T16:29:53.075Z] The listener for function 'Functions.blobCheck' was unable to start. Azure.Core: Retry failed after 6 tries. Retry settings can be adjusted in ClientOptions.Retry. (Connection refused ( (Connection refused ( (Connection refused ( (Connection refused ( (Connection refused ( (Connection refused ( Azure.Core: Connection refused ( System.Net.Http: Connection refused ( System.Private.CoreLib: Connection refused.
[2022-04-09T16:29:53.078Z] Host started (26250ms)
[2022-04-09T16:29:53.078Z] Job host started
[2022-04-09T16:29:53.176Z] Stopping host...
[2022-04-09T16:29:53.191Z] Stopping JobHost
[2022-04-09T16:29:53.200Z] Job host stopped
info: Grpc.AspNetCore.Server.ServerCallHandler[14]
      Error reading message.
      System.IO.IOException: The request stream was aborted.
       ---> Microsoft.AspNetCore.Connections.ConnectionAbortedException: The HTTP/2 connection faulted.
         --- End of inner exception stack trace ---
         at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
         at System.IO.Pipelines.Pipe.GetReadAsyncResult()
         at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2MessageBody.ReadAsync(CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at Grpc.AspNetCore.Server.Internal.PipeExtensions.ReadStreamMessageAsync[T](PipeReader input, HttpContextServerCallContext serverCallContext, Func`2 deserializer, CancellationToken cancellationToken)
[2022-04-09T16:29:53.227Z] Host shutdown completed.
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'gRPC - /AzureFunctionsRpcMessages.FunctionRpc/EventStream'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/2 POST application/grpc - - 200 - application/grpc 25910.1334ms
info: Microsoft.AspNetCore.Server.Kestrel[32]
      Connection id "0HMGQ8OEPFOF0", Request id "0HMGQ8OEPFOF0:00000001": the application was completed without reading the entire request body.

The host in local settings json file is but in the error above it says Connection refused ( why is it trying to connect the localhost?

Also, I am working on an azure compute connected via vscode. Is this error related to that?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,000 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 12,731 Reputation points

    Hi @Obaid UrRehman ,

    Welcome to Microsoft Q&A! Thanks for posting the question.

    I see that you are trying to develop Blob triggered Azure Function using Python. Please refer to this link for a quickstart guide - Azure Blob storage trigger for Azure Functions.

    From the shared information above, I can see 2 main issues:

    1. You have selected "AzureWebJobsStorage": "UseDevelopmentStorage=true" for AzureWebJobsStorage. This uses Azure Storage Emulator/Azure Azurite installed on the dev machine as storage for Azure Function which is required for Azure Function to run.
    Please ensure that "Azure Storage Emulator" is installed on the local machine and is running. The error mentioned seems to be related to that.

    2. The Trigger binding as available in function.json uses the connection string labelled AzureWebJobsStorage. This connection string is available in local.settings.json as "AzureWebJobsStorage": "UseDevelopmentStorage=true",.

    This means that you are using the local storage emulator for blob triggered Azure Function. The other settings of local.settings.json are not being used.

    If you are trying to use blobs in "Azure Storage" to trigger "Azure Function", please change the connection in function.json to another label and associate it with the Connection String of the storage account. The following is a sample:



    The connection string ("storage4266_STORAGE" in above example) can be obtained from Azure Storage --> Access Keys.

    Please let me know if you have any questions.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful