Skip to content

[BUG]Dead loop occurs when NextPageLink is not null but resource results are empty #996

Closed

Description

Describe the bug
In the method AddCollection of class PagedCollection, there is dead-loop when the resources returned from service are empty but next-page-link is not null.

It should continue invoking requests to get more results based-on next-page-link until it reaches to null. It cannot assume there are no more results because the current results are empty. The common practice is to follow the next-page-link until it reaches to null, which indicates no more results from server.

Exception or Stack Trace
No exception but dead-loop occurs.

To Reproduce
Mock up a Page’s data returned from server to zero records but NextPageLink is not null.

Code Snippet
The code is in file src\ResourceManagement\ResourceManager\Core\PagedCollection.cs.

The existing code:
private async Task AddCollection(IPage currentPage, PagedCollection<IFluentResourceT, InnerResourceT> pagedCollection,
CancellationToken cancellationToken)
{
if (currentPage != null && currentPage.Any())
{
pagedCollection.NextPageLink = currentPage.NextPageLink;
var resources = await Task.WhenAll(currentPage.Select(async (inner) => await this.WrapModelAsyncDelegate(inner, cancellationToken)));
((List)pagedCollection.innerCollection).AddRange(resources);
}
}

This code will cause dead-loop in method LoadPageWithWrapModelAsync‘s do-while loop when currentPage.Any() is false since pagedCollection.NextPageLink is NOT updated with next one.

Expected behavior
private async Task AddCollection(IPage currentPage, PagedCollection<IFluentResourceT, InnerResourceT> pagedCollection,
CancellationToken cancellationToken)
{
if (currentPage != null)
{
pagedCollection.NextPageLink = currentPage.NextPageLink;
if (currentPage.Any())
{
var resources = await Task.WhenAll(currentPage.Select(async (inner) => await this.WrapModelAsyncDelegate(inner, cancellationToken)));
((List)pagedCollection.innerCollection).AddRange(resources);
}
}
}
This will pass current page NextPageLink to pagedCollection’s one. It will continue making requests by following the next link until it reaches null and stop looping in method LoadPageWithWrapModelAsync‘s do-while loop.

Setup (please complete the following information):

  • OS: Windows 10
  • IDE : Visual Studio 2017
  • Version of the Library used: Fluent 1.15.1 and 1.30.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    BugMgmtManagement plane SDK related issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions