question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No Cancellation Token on Azure Function Method

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
tidusjarcommented, Mar 12, 2021

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.

7reactions
SeanFeldmancommented, Jul 12, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found