Timeout while getting list of items in Sharepoint Document Library (C# ASP DotNet) (started 23/09/2022)

Barnes Daniel 1 Reputation point
2022-09-27T08:02:38.443+00:00

I'm using Microsoft Graph API to get a list of documents in a Sharepoint Document Library. Code was fine for 6 months. Last Friday my code broke.

There are about 700 documents in the library, and in the past the request would complete after 5-6 seconds. As of last Friday (23/09/2022) it started timing out after (~120 seconds). If I limit it to 200 rows, it works after 12 seconds, but I need all 700! If there is a way to do paging that could work, then I could make my own method. Also if I could increase the timeout it might work - I have tried modifying both the GraphClient.HttpProvider.OverallTimeout and the request .WithMaxRetry to 900 seconds, but it still times out after around 122 seconds.

Here is the relevant part of my code (rowLimit is an int set to 5000):

List<QueryOption> queryOptions = new List<QueryOption>()  
            {  
                new QueryOption("Top", $"{rowLimit}"),  
                new QueryOption ("Prefer","allowthrottleablequeries")  
            };  
  
IDriveItemChildrenCollectionPage result = await GraphClient.Sites[siteID].Drives[documentLibraryID].Root.Children  
                    .Request(queryOptions)  
                    .Expand("listItem")  
                    .WithMaxRetry(1) //set 1 max retry and set timeout  
                    .WithMaxRetry(TimeSpan.FromSeconds(900)  
                    .GetAsync();  

After ~122 seconds I receive the following exception: Code: tooManyRetries Message: More than 1 retries encountered while sending the request.

As mentioned, I can get it to work if I limit the number of rows - 200 rows return in around 12 seconds, 400 rows return in around 24 seconds. The strange thing is it was fine last week, so perhaps Microsoft changed something?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,166 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,248 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Barnes Daniel 1 Reputation point
    2022-09-27T23:13:38.647+00:00

    I managed to work around my issue by using pagination:

    List<DriveItem> allItems = new();  
      
    var result = await GraphClient.Sites[siteID].Drives[documentLibraryID].Root.Children  
                    .Request()  
                    .Expand("listItem")  
                    .Top(100)  
                    .GetAsync();  
      
                var pageIterator = PageIterator<DriveItem>  
                    .CreatePageIterator(  
                        GraphClient,  
                        result,  
                        (item) =>  
                        {  
                            allItems.Add(item);  
                            return true;  
                        });  
      
                await pageIterator.IterateAsync();  
    

    This way I get the results 100 at a time, which was within the timeout threshold. They are then all added to a List (allItems) so I didn't need to change the rest of my code.

    0 comments No comments