Clarify CancellationToken binding vs CancellationToken from FunctionContext vs CancellationToken from HttpContext in HTTP Trigger #2928
Replies: 2 comments 1 reply
-
Hiii, I'm also curious to get an answer to this seemingly trivial question. Kind regards and thanks in advance |
Beta Was this translation helpful? Give feedback.
-
Hey, so you're pretty much spot on here. But the
Correct
Yup, also correct (keeping in mind the bound CT and context CT are the same CT). If I had to choose, I would suggest only using the
Yeah the documenation is not great, I have a work item to get those docs updated. There's a draft of the text for this doc update here (in the issue) - I'll see if I can get more input on this in our next sprint. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hii,
I've gotten questions from colleagues the past few days regarding the usage of CancellationTokens in an HTTP triggered function and I noticed that both in the documentation and on the internet, there's some ambiguity/discussions on when to use either token. Hence this discussion.
As mentioned in the title, I'm aware of 3 ways of acquiring a CancellationToken.
First of all, I'd like to believe that the CancellationToken binding is just a convenience shortcut for the one found in the
FunctionContext
. However, the documentation (here and here) aren't exactly clear and only states that it is used for graceful shutdown. No word on mentioning that it can also be used for a request timing out, connection getting dropped or a user aborting the request.TL;DR Only when the function app is getting shut down.
The
RequestAborted
CancellationToken, on the other hand, will probably just be a HTTP trigger specific CancellationToken that only reacts to consumers dropping the call.With that all being said, I also stumbled upon this PR in the Azure Functions host repo, which would in turn would mean that the
RequestAborted
CancellationToken is getting linked to the both the CancellationToken inFunctionContext
, as well as the one that can be bound as a method parameter (assuming that my previous assumption still holds up) and thus, that we should just use either of the latter ones.I'd appreciate it if someone could clarify this and either confirm or deny my assumptions so we can get a better understanding of it all :)
Beta Was this translation helpful? Give feedback.
All reactions