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

[core-lro] Set isCancelled when operation status is cancelled #21893

Merged
merged 12 commits into from
May 18, 2022

Conversation

deyaaeldeen
Copy link
Member

@deyaaeldeen deyaaeldeen commented May 16, 2022

The cancel operation on the poller can be implemented dynamically by passing a function to the cancel option in the lroEngine's options bag. However, @witemple-msft pointed out that the poller is being marked as cancelled prematurely before even calling the user-provided cancel callback.

I remedied this situation by:

  1. updating the cancel API to not set isCanceled in the poller's state at all and leave that to the library author to do inside their callbacks set isCanceled after the cancellation callback fully resolves.
  2. updating the polling implementation to set isCanceled if the operation status returned from the service is set to canceled.

The change #1 is needed because polling stops if poller.cancelOperation() fully resolves so there is no chance for the change #2 to kick in and set isCanceled accordingly.

The change #2 is needed because cancellation could originate from places other than the poller at hand.

One important behavioral change in this PR to call out is that an operation status set to canceled caused the poller to throw an error saying the operation has failed. With this PR, canceling a POST LRO request will no longer throw an error by default. I believe this behavioral change is necessary because some POST LROs support access to partial results even if the operation was canceled (Text Analytics for example). However, library authors can throw errors manually in their callbacks as needed.

Please note that this PR is scoped to fixing the issue of prematurely setting isCanceled. I am happy to look at any feature requests or other issues in other github issues/pull requests.

@azure-sdk
Copy link
Collaborator

API change check for @azure/core-lro

API changes are not detected in this pull request for @azure/core-lro

@azure-sdk
Copy link
Collaborator

API change check for @azure/ai-text-analytics

API changes are not detected in this pull request for @azure/ai-text-analytics

* so throwing an error in this case could be prevent customer from getting
* access to those partial results.
*/
if (["PUT", "DELETE", "PATCH"].includes(lro.requestMethod) && status === "canceled") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't throw even in PUT, DELETE and PATCH. Would users get stuck in a weird state or just wouldn't have interesting information in the request?

If they don't end up in a bad place, would it make sense to not throw and have everything fall into the next check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pollUntilDone() method returns a result so if no error was thrown, it will return an object with a status field set to canceled as the result and it most likely will not match the expected type of the result object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the behavioral change for now and kept the original behavior of throwing in all cancellation scenarios. I will explore not throwing for POST requests in another PR.

@deyaaeldeen deyaaeldeen marked this pull request as ready for review May 17, 2022 21:29
@deyaaeldeen deyaaeldeen requested a review from xirzec as a code owner May 17, 2022 21:29
@Azure Azure deleted a comment from check-enforcer bot May 18, 2022
@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

@deyaaeldeen deyaaeldeen requested a review from joheredi May 18, 2022 06:30
Copy link
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes make sense to me, and thanks for adding the tests to confirm.

I only have one comment about the version policy.

sdk/textanalytics/ai-text-analytics/package.json Outdated Show resolved Hide resolved
@deyaaeldeen deyaaeldeen merged commit 51f5be7 into Azure:main May 18, 2022
@deyaaeldeen deyaaeldeen deleted the core-lro/status-sets-iscancelled branch May 18, 2022 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants