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

Validate that timeout is positive in WaitForOrchestrationAsync, and enable nullable checks #910

Conversation

davidmrdavid
Copy link
Collaborator

@davidmrdavid davidmrdavid commented May 26, 2023

This PR validates that the timeout in WaitForOrchestrationAsync is positive. Otherwise, we risk accidentally returning null without doing any meaningful work.

This PR also enables nullable analysis for part of the AzureStorageOrchestrationService file

I encountered this in the process of repro'ing this issue: microsoft/durabletask-dotnet#143

@@ -1857,6 +1856,13 @@ async Task<PurgeResult> IOrchestrationServicePurgeClient.PurgeInstanceStateAsync
throw new ArgumentException(nameof(instanceId));
}

if (timeout < TimeSpan.Zero)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we accept negative values? There seems to be a precedence that negative implies infinite for timeouts. Especially since Timeout.InfiniteTimeSpan is negative.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, I think it's up for debate, and I no strong feelings on this. I simply noticed that the code today assumes the timeout will be positive, and so I made that assumption explicit by validating the input.

Using a combination of Datetime.now and the provided timespan, we can modify the currrent implementation to work with infinite timespans as well.

Would you prefer if we accepted negative timespans? I see no issue with that

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be a better experience to accept negative as an infinite timeout.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd say let's be specific and allow for Timeout.InfiniteTimeSpan to mean infinite, whereas we throw for any other negative value. I believe this is mostly consistent with other .NET APIs and helps us differentiate an explicit desire for infinite vs. an accidental negative value provided by the user.

So here, I think we'd say if (timeout < TimeSpan.Zero && timeout != Timeout.InfiniteTimeSpan) and below, we change the while loop condition to be while (!cancellationToken.IsCancellationRequested) (removing the timeout check).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like the compromise of explicitly checking for Timeout.InfiniteTimeSpan, and erroring out in other negative TimeSpan cases. My latest commit tries to do just that.

My if statement is as you suggested, @cgillum. However, the while loop does preserve the timeout check because I think we need it for the "happy case" where the timeout is positive. I suppose I could also move it to an if-statement check inside the while loop though.

Copy link
Collaborator

@cgillum cgillum left a comment

Choose a reason for hiding this comment

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

Happy to see you decided to support Timeout.InfiniteTimeSpan. :)

Added some non-blocking suggestions. I realize the one regarding TimeSpan.Zero would require some refactoring for a "perfect" implementation, so I'm fine if you want to skip that.

@davidmrdavid
Copy link
Collaborator Author

@cgillum: let's try to get this right all the way. Does this latest commit look good to you?

Copy link
Collaborator

@cgillum cgillum left a comment

Choose a reason for hiding this comment

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

LGTM!

@davidmrdavid davidmrdavid merged commit 0159481 into main Jun 2, 2023
2 checks passed
@davidmrdavid davidmrdavid deleted the dajusto/check-for-negative-timespan-waitForOrchestrationAsync branch June 2, 2023 23:24
wsugarman pushed a commit to wsugarman/durabletask-azurestorage-scaler that referenced this pull request Jun 20, 2023
…2.9.6 (#252)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[Microsoft.Azure.WebJobs.Extensions.DurableTask](https://togithub.com/Azure/azure-functions-durable-extension)
| nuget | patch | `2.9.5` -> `2.9.6` |

---

### Release Notes

<details>
<summary>Azure/azure-functions-durable-extension</summary>

###
[`v2.9.6`](https://togithub.com/Azure/azure-functions-durable-extension/releases/tag/v2.9.6):
Durable Functions v2.9.6


https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.DurableTask/2.9.6

### Bug fixes

- DT.AzureStorage: Add validation check for the timeout in
WaitForOrchestrationAsync
([Azure/durabletask#910)
- Fixed issue of missing dedupe states in the gRPC server client when
scheduling a new orchestration via IOrchestrationServiceClient
([#&#8203;2489](https://togithub.com/Azure/azure-functions-durable-extension/issues/2489))
- Improved GRPC exception type and message when creating duplicate
instances
([#&#8203;2493](https://togithub.com/Azure/azure-functions-durable-extension/issues/2493))

### Dependency Updates

- [DurableTask.AzureStorage to
v1.13.8](https://togithub.com/Azure/durabletask/releases/tag/durabletask.azurestorage-v1.13.8)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/wsugarman/durabletask-azurestorage-scaler).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMzEuMCIsInVwZGF0ZWRJblZlciI6IjM1LjEzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

3 participants