Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cancellation token if function is invoked before cancellation token #2546

Merged
merged 5 commits into from
Jul 2, 2024

Conversation

aishwaryabh
Copy link
Contributor

@aishwaryabh aishwaryabh commented Jun 20, 2024

Issue describing the changes in this PR

resolves #2415

We had a design discussion about this issue and came to the conclusion that we will not use the cancellation token in the pipeline and instead invoke CancellationToken.None. That way the customer can still have their function be invoked and handle the cancellation token as they want within their code.

To test this out I did the following from guidance from Lilian:

  1. use this sample for the worker app: sample

  2. Updated the tsc here to cancel the token after 5 seconds.

  3. Invoked the HttpTriggerWithCancellation function, set a breakpoint after the token was cancelled, resumed function execution, and saw that a TaskCancelledException was invoked when the pipeline's cancellation token was passed in. With my changes, I saw that I was able to modify the function to handle the cancellation token as I wish.

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Additional PR information

@jviau
Copy link
Contributor

jviau commented Jun 24, 2024

The build errors appear unrelated to your change, but I am unsure how they appeared in the first place.

@kshyju
Copy link
Member

kshyju commented Jun 26, 2024

Looks like none of the tests in DefaultModelBindingFeatureTests is using a valid cancellation token flow (All of them uses CancellationToken.None). Should we add/update test(s) to reflect that?

@kshyju
Copy link
Member

kshyju commented Jun 26, 2024

The build errors appear unrelated to your change, but I am unsure how they appeared in the first place.

We had some wildcard pattern used for nuget packages and one of the package had a patch version bump a week ago, which brought a new version of NuGet.Common package as a transitive dependency. Our tests files were pinned to a lower version of NuGet.Common package and that caused the error.

@aishwaryabh Please rebase after #2549 is merged.

@aishwaryabh
Copy link
Contributor Author

Added a unit test to handle the cancellation token

@aishwaryabh aishwaryabh merged commit d5b185e into main Jul 2, 2024
29 checks passed
@aishwaryabh aishwaryabh deleted the aibhandari/cancellation-token branch July 2, 2024 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected TaskCancelledException caused by pre-cancelled CancellationToken
3 participants