Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Don't signal shutdown Cancellation Token when starting Drain Mode and include end to end tests #2795

Open nzthiago opened 3 years ago

nzthiago commented 3 years ago

Customers don't expect a shut down Cancellation Token (related: #2782) when the host enters drain mode.

To ensure currently executing .NET in process functions are allowed to complete successfully we should not signal a host shutdown cancellation token when entering drain mode.

Also as part of the Drain Mode End to End Tests we should have one or more end to end tests that has:

Tasks

liliankasem commented 3 years ago

Potentially related to https://github.com/Azure/azure-webjobs-sdk/issues/2776

es-alt commented 2 years ago

@soninaren , what nuget version is this in?

soninaren commented 2 years ago

@soninaren , what nuget version is this in?

Should be version 3.0.33. I don't think it has been released yet.

es-alt commented 2 years ago

@soninaren , this affects us a lot in production with HttpTriggered functions. Is there at least an approximate estimate of when 3.0.33 can be released?

soninaren commented 2 years ago

@lecamarade are you using the webjobs sdk or a function app. I think the function release is already in progress.

es-alt commented 2 years ago

@soninaren , we use a function app. If release is in progress, are we talking, days, weeks or months?

soninaren commented 2 years ago

@soninaren , we use a function app. If release is in progress, are we talking, days, weeks or months?

Based on the current release progress it looks like it should be complete in a couple of weeks.

mathewc commented 1 year ago

Reactivating this because we're seeing inconsistent behavior across various extensions when drain is initiated. For example, the latest versions of both the Azure Queues and ServiceBus extensions trigger the cancellation token when drain is started.

drdamour commented 1 year ago

i've been using azure functions for going on 4 years and drain mode is still a mystery to me. I had incorrectly assumed that it WOULD send cancellation tokens and got really confused when it did for some extensions and not for others. Seems like some docs around drain mode are missing in the az function space and it should be encouraged for extensions to document their expected drain mode behaviour

the recent "fix" in event hub extension pointed out IDrainModeManager which i had never come across in the Az functions docs.

limited results from google on this, some appear to be completely wrong like https://learn.microsoft.com/en-us/answers/questions/770912/why-do-i-see-drainmode-mode-enabled-in-the-logs-an?source=docs

At this time, it sends a request to the Admin API to enter drain mode. Then all currently executing Functions on that instance receive a cancellation token which the customer can handle.

emphasis added.

and https://datanrg.blogspot.com/2021/06/azure-function-drain-mode.html

When the host is put in drain mode, It should: Stop listening for new incoming requests, Cancellation token is passed as a parameter to the function invocation, Finally, a scale-in operation is performed.

liliankasem commented 1 year ago

@drdamour IDrainModeManager is for internal use and is not intended for customers to use in their applications so you will not hear about this in the docs anywhere.

The intended behaviour for drain mode is:

  1. Stop listening for new incoming requests
  2. Allow existing function invocations to finish executing without interruption
  3. Scale-in operation is performed when all invocations are completed

I think there was some miscommunication on the intended behaviour which is why some extensions send a cancellation token and some don't, this is something that is actively being fix across the board.

drdamour commented 1 year ago

@liliankasem um.... then why is it being advertised for use in recent release notes?

https://github.com/Azure/azure-sdk-for-net/blob/Microsoft.Azure.WebJobs.Extensions.EventHubs_5.5.0/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/CHANGELOG.md

https://github.com/Azure/azure-sdk-for-net/blob/Microsoft.Azure.WebJobs.Extensions.ServiceBus_5.12.0/sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/CHANGELOG.md

liliankasem commented 1 year ago

🤷‍♀️ news to me

drdamour commented 1 year ago

well...if it works as advertised it certainly fulfills a need i as an app developer have, though more in the durable functions space of knowing when my instance has entered drain mode.