Description
openedon Mar 6, 2020
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.