No Cancellation Token on Azure Function Method
See original GitHub issueIn the previous framework, I could pass a cancellation token to an Azure Function Method:
[FunctionName("my-function")]
public async Task<IActionResult> MyFunction(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
CancellationToken cancellationToken)
{
...
}
if I try and do that now, an error occurs when calling the method with the cancellation token:
[FunctionName("my-function")]
public async Task<HttpResponseData> MyFunction(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req,
FunctionExecutionContext executionContext),
CancellationToken cancellationToken)
{
...
}
This is the error that occurs when calling the method:
[2021-02-05T01:44:09.069Z] System.Private.CoreLib: Exception while executing function: Functions.migrate. System.Private.CoreLib: Result: Failure
Exception: Sequence contains no elements
Stack: at System.Linq.ThrowHelper.ThrowNoElementsException()
[2021-02-05T01:44:09.070Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionExecutionContext context)
[2021-02-05T01:44:09.071Z] at Microsoft.Azure.Functions.Worker.FunctionBroker.InvokeAsync(InvocationRequest invocationRequest) in D:\a\1\s\src\DotNetWorker\Broker\FunctionBroker.cs:line 44.
Will support be added back in for the tokens?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:18
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Azure Functions using Cancellation Token with Http Trigger
The token passed in Function Method parameter is the Host Cancellation Token - cancellation is requested when the host is about to shut...
Read more >Develop C# class library functions using Azure Functions
A function can accept a CancellationToken parameter, which enables the operating system to notify your code when the function is about to be ......
Read more >A Cancellation Token, an Azure Function and managing ...
In summary, a cancellation token is helpful to manage the shutdown of your code on a server/VM when the server/VM are being shutdown....
Read more >Best Practices for Graceful shutdown in Azure Functions
CancellationToken provides a means to cancel general asynchronous processing in .NET. Azure Functions has built-in support for CancellationToken ...
Read more >Azure Function App Graceful Shutdown
You can specify the CancellationToken parameter which will notify you code whenever function is going to terminate.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is there any update on this?
I’d like to understand the reasoning behind removing the cancellation token, especially in the case of HttpTriggerFunctions where using a
CancellationToken
makes A LOT of sense.This is a bit of a deal breaker personally for me as I feel like this is a step backwards and is preventing me from upgrading to net core 5.
This is why the SDK should provide cancellation token rather than developers come up with their own solutions and recreated the same thing time and time again. From all the things that are being improved with the isolated worker, this feels like a step in the wrong direction. @fabiocav any plans to address this?