Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Azure functions .NET Core 2.1 not woken up by messages on Service Bus after inactivity

Open madnessaa opened this issue 7 years ago • 18 comments

Azure functions application targeting framework .NET Core 2.1 on consumption plan is not woken up by messages on Service Bus subscription once it goes idle / to sleep due inactivity.

Error displayed when trying to browse function during its downtime is as follows: HTTP Error 500.30 - ANCM In-Process Start Failure Common causes of this issue: The application failed to start The application started but then stopped The application started but threw an exception during startup Troubleshooting steps: Check the system event log for error messages Enable logging the application process' stdout messages Attach a debugger to the application process and inspect For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265

Messages are saved in subscription queue and not processed until we manually restart (stop/start) function in the portal. At that moment all messages processing continues correctly until it goes idle again.

We used Visual Studio to deploy function application to our DEV environment and we also used sync trigger endpoints to manually sync but that didn't help.

Once application is warmed up, all works correctly.

Application NuGet Packages: Microsoft.NET.Sdk.Functions 1.0.26 Microsoft.Azure.WebJobs.Extensions.Storage 3.0.5 Microsoft.Azure.WebJobs.Extensions.ServiceBus 3.0.4 Microsoft.Azure.WebJobs.Extensions.DurableTask 1.8.0

Invocation details after function has been restarted after previously failed:

  • Timestamp: 2019-06-19T06:40:06.423
  • Function App version: 2.0
  • Invocation ID: 13ff84a3-13e4-4758-a18c-a394a4f85881
  • Region: EAST US

Repro steps

  1. Function is idle
  2. Message gets to service bus subscription
  3. Function is still idle and not being woken up by new message on service bus subscription
  4. Manual stop and start of the function
  5. Messages are processed

madnessaa avatar Jun 19 '19 06:06 madnessaa

Same issue here

jwisener avatar Jul 15 '19 11:07 jwisener

@jeffhollan or @ColbyTresness , no response to this in 26 days? this seems like a big issue, right now it's a huge blocker for us.

jwisener avatar Jul 15 '19 16:07 jwisener

Looks like this one fell through the cracks, sorry about that. @maiqbal11 to investigate

ColbyTresness avatar Jul 15 '19 20:07 ColbyTresness

We are still experiencing this issue. We implemented an ugly workaround by using timer function that keeps Function App instance alive, but that beats the whole purpose of the Consumption Plan. Each time we disable the timer function the issue happens again. We tried upgrading the NuGet packages but that didn't help. Also none of the other functions (hosted inside the same Function app) that work with Service Bus subscriptions do not wake up the instance or spin up the new one.

madnessaa avatar Jul 16 '19 10:07 madnessaa

@fabiocav same thing here. @maddnessaa yeah same thing for us. I thought I had fixed it. But it’s the same behaviour as you are experiencing.

jwisener avatar Jul 16 '19 11:07 jwisener

We experience the same issue. Any ETA for a fix?

srieppo2 avatar Aug 27 '19 08:08 srieppo2

The issue turned out for us to be the service connection string “key name” has to be named AzureWebJobsServiceBus and must be in the app settings, if not the scale controller (the code/process that is responsible for calling your function, that you have no control over) uses and looks specifically for that key name. That key name must be : AzureWebJobsServiceBus

jwisener avatar Aug 27 '19 12:08 jwisener

The issue turned out for us to be the service connection string “key name” has to be named AzureWebJobsServiceBu

Thanks for the info. I will try that

srieppo2 avatar Aug 27 '19 13:08 srieppo2

This has been an issue we have dealt with for a long time. We also did the keep-alive timer function.

We have no HTTP triggers, which the documentation mentions are the only ones that wake up your function application when running on an App Service Plan. It says that when running on Consumption Plan, Azure will automatically wake up the application. We have primarily Service Bus triggers, and a few Storage triggers. After our Consumption Plan Function App goes into the idle state, it literally does not wake up until I sign in to Azure Portal and view the resource. It's not that there's a cold start of 5 minutes, or even an hour, that I'm not waiting for. It's that it never wakes back up - many hours later - until I manually sign into the Azure Portal and view the resource.

My guess is that if I add an HTTP trigger, that might wake it up.

Our connection string for Service Bus has always been AzureWebJobsServiceBus, as @jwisener points out. So that may be one required element, but does not fix the wake up issue apparently.

Again, this is something we've dealt with for the past 2 years.

/cc: @alexkarcher-msft @jeffhollan @christopheranderson @gzuber

ryancole avatar Dec 02 '20 15:12 ryancole

@maiqbal11

I found this thread because I was experience the same issue. We are using C# Azure Functions, running on Functions v3 and .NET Core 3.1, with the ServiceBusTrigger listening on a Service Bus queue.

After breaking these functions into separate Function App projects, we started seeing the issue exactly as @ryancole described. The function app would not trigger for hours, despite having >100 messages waiting in the queue. If I opened the Function App in the portal and clicked 'Browse' it would start right up and begin processing successfully. Our deployment process was as follows:

  1. Create Azure Function App with ARM template
  2. Deploy application as ZIP Deploy/WEBSITE_RUN_FROM_PACKAGE
  3. Restart the Function App

What I believe has fixed the issue is adding an Application Setting to the function app named ConnectionStrings:AzureWebJobsServiceBus, with the ServceBus connection string as the value. Note we already had a ServiceBus connection string set in the 'Connection Strings' portion of the Function App Configuration blade. This connection string worked at least in terms of the Function execution itself. Nowhere in our application is a connection string name specified. I'm hoping for confirmation that Function App itself recognizes the ServiceBus connection string setting by default, but the scale controller does not. If that is the case, I believe this is a bug - both components should recognize the same default connection strings. At the least this should be documented somewhere if it is not.

After adding this setting, the Function App does start automatically after messages are sent, although there is the (expected) cold start, with an initial delay of 15-30 seconds. Previously, our functions were in a shared Function App project that happened to have a TimerTrigger function which I believe was, by chance, saving us from this issue.

SamNutkins avatar Mar 08 '21 23:03 SamNutkins

Dealing with the same issue. Updating the application setting name didn't fix. Is this still being looked into?

gma2222 avatar Oct 11 '21 20:10 gma2222

The same issue still exists one year later. Is anyone found a fix expect workaround with the time trigger ?

MindForks avatar Oct 25 '22 21:10 MindForks

The same issue still exists one year later. Is anyone found a fix expect workaround with the time trigger ?

did you trying naming your servicebus connection string: AzureWebJobsServiceBus

jwisener avatar Oct 25 '22 21:10 jwisener

@jwisener yes, I've added AzureWebJobsServiceBus connection string and removed the connection string from the method signature.

Now it looks like this:

[FunctionName("fx")] public async Task RunAsync([ServiceBusTrigger("topic", "inner-subscription")] string myQueueItem, ILogger log) { }

is it correct?

MindForks avatar Oct 25 '22 21:10 MindForks

That looks right to me.

jwisener avatar Oct 26 '22 00:10 jwisener

I think we also ran into an issue where we had multiple app instances (azure function apps) had the same ‘blob storage location’. If I remember correctly (was so long ago), when one instance would spin up, we would lose the functions in the other function app instance (aka stop working, functions seem to disappear). It was hard to trouble shoot because we would stop and start the instance and then it would work, but as soon as another app instance would start up we would (lose functions in the other). It was difficult to see. We had to ensure the storage location was different for each one.

jwisener avatar Oct 26 '22 02:10 jwisener

My Function App has 2 funcs, both of which use Service Bus Triger on different Service Bus App. The single storage account used for this function app

MindForks avatar Oct 26 '22 20:10 MindForks

Sounds like you got it all setup correctly, should be working.

On Wed, Oct 26, 2022 at 3:05 PM Mike @.***> wrote:

My Function App has 2 funcs, both of which use Service Bus Triger. The single storage account used for this function app

— Reply to this email directly, view it on GitHub https://github.com/Azure/Azure-Functions/issues/1254#issuecomment-1292594092, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBETQDMS4JI2NLVNPJJZDWFGFKLANCNFSM4HZGOWTA . You are receiving this because you were mentioned.Message ID: @.***>

jwisener avatar Oct 26 '22 23:10 jwisener