Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.91k stars 437 forks source link

Graceful shutdown of a `QueueTrigger` isolated function via `CancellationToken` #10265

Open jonsagara opened 3 weeks ago

jonsagara commented 3 weeks ago

Hello,

In my .NET 8 dotnet-isolated QueueTrigger Azure Function, I'm unable to observe shutdown notices via the injected CancellationToken. This occasionally leaves my application in an unfinished, indeterminate state:

2024-06-05 02:31:15.782 [Information] [redacted legitimate activity, 1/250]
2024-06-05 02:31:15.860 [Information] [redacted legitimate activity, 2/250]
2024-06-05 02:31:15.866 [Information] [redacted legitimate activity, 3/250]
2024-06-05 02:31:16.233 [Information] [Microsoft.Hosting.Lifetime] Application is shutting down...
2024-06-05 02:31:31.133 [Information] [Microsoft.Hosting.Lifetime] Application started. Press Ctrl+C to shut down.

I opened an issue on the azure-functions-dotnet-worker repo about a month ago, but I haven't received any response.

I describe the issue fully over there, and I also have a full reproduction here. It shows that the CancellationToken works with .NET 6 in-process, but not with .NET 6 or .NET 8 isolated.

Will you please take a look at the issue and, if appropriate, move it to this repository?

Thank you,

Jon

Expected behavior

A dotnet-isolated QueueTrigger function should be able to observe a CancellationToken and gracefully shutdown.

Actual behavior

A dotnet-isolated QueueTrigger function cannot observe a CancellationToken and gracefully shutdown.

bhagyshricompany commented 2 weeks ago

thanks for reporting .please update all sdk with latest one.Thanks

jonsagara commented 2 weeks ago

Hi,

I upgraded my repro to the latest SDK and I'm using the latest VS 2022 preview:

.NET SDK 8.0.303 VS 2022 Preview 17.11.0 Preview 3.0

Packages in .NET 6 in-process:

<ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.3.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
</ItemGroup>

Packages in .NET 6 isolated:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.4.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
</ItemGroup>

Packages in .NET 8 isolated:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.4.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
</ItemGroup>

The behavior is still the same:

Thanks,

Jon