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

Invalid continuation token in GetStatusAsync API #1174

Closed
f2bo opened this issue Jan 21, 2020 · 6 comments
Closed

Invalid continuation token in GetStatusAsync API #1174

f2bo opened this issue Jan 21, 2020 · 6 comments
Assignees
Labels
Milestone

Comments

@f2bo
Copy link

f2bo commented Jan 21, 2020

Description

The new paged GetStatusAsync API appears to return an invalid continuation token when there are no more results.

Expected behavior

The behavior is not documented, and I hadn't used this overload previously so this may be a bad assumption on my part, but I expected GetStatusAsync to return a null continuation token once it completes the enumeration.

Actual behavior

Instead, it returns "bnVsbA==", which when base64 decoded corresponds to "null" as a string.

The loop in the following method never exits because the ContinuationToken is never null. The first iteration of the loop returns the expected results (2 in my test case) and "bnVsbA==" as the continuation token. Then it just keeps returning the same results in subsequent iterations.

private async Task<IEnumerable<string>> GetChildOrchestrations(
    IDurableOrchestrationClient client,
    string instanceIdPrefix,
    CancellationToken cancellationToken = default)
{
    var children = new List<string>();

    var queryCondition = new OrchestrationStatusQueryCondition
    {
        InstanceIdPrefix = instanceIdPrefix,
        ShowInput = false,
        ContinuationToken = null
    };

    do
    {
        var status = await client.GetStatusAsync(queryCondition, cancellationToken);
        queryCondition.ContinuationToken = status.ContinuationToken;

        children.AddRange(status.DurableOrchestrationState.Select(p => p.InstanceId));
    } while (queryCondition.ContinuationToken != null && !cancellationToken.IsCancellationRequested);

    return children;
}

App Details

  • Durable Functions extension version: v2.1.1:
  • Azure Functions runtime version 2.0:
@ghost ghost added the Needs: Triage 🔍 label Jan 21, 2020
@f2bo
Copy link
Author

f2bo commented Jan 30, 2020

So, should we just test for the end of the enumeration against "bnVsbA=="?

do
{
    var status = await client.GetStatusAsync(queryCondition, cancellationToken);
    ...
    queryCondition.ContinuationToken = status.ContinuationToken;
} while (queryCondition.ContinuationToken != "bnVsbA==");

If not, how do you use this API? The documentation does not mention this, or at least, I can't find it in either of these two pages.

https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-instance-management

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableorchestrationclient.getstatusasync?view=azure-dotnet#Microsoft_Azure_WebJobs_Extensions_DurableTask_IDurableOrchestrationClient_GetStatusAsync_Microsoft_Azure_WebJobs_Extensions_DurableTask_OrchestrationStatusQueryCondition_System_Threading_CancellationToken_

@cgillum
Copy link
Collaborator

cgillum commented Jan 30, 2020

Hi @f2bo yeah, this looks pretty broken. I think your workaround for now is okay, but this definitely needs to be fixed. Thanks for raising the issue and providing a repro.

@cgillum cgillum added this to the v2.2.0 milestone Jan 30, 2020
@f2bo
Copy link
Author

f2bo commented Jan 30, 2020

Thanks @cgillum.

Just to be safe, the fix will be to return null instead, correct? So, once the bug is fixed, we'll still be fine if we check this as:

while (queryCondition.ContinuationToken != null && queryCondition.ContinuationToken != "bnVsbA==");

@cgillum
Copy link
Collaborator

cgillum commented Jan 30, 2020

Yes, this is definitely a good idea.

@ConnorMcMahon
Copy link
Contributor

PR to handle this here: Azure/durabletask#372

@ConnorMcMahon
Copy link
Contributor

Fixed in 2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants