We have some old timer jobs that have been developed some years ago, but we recently rewritten in an attempt to enhance the performance and prevent some issues like SharePoint Search encountered a problem and timeout issues following the guidelines here: https://learn.microsoft.com/en-us/sharepoint/dev/general-development/pagination-for-large-result-sets
Our initial tests showed this was working great, but now we are starting to see the same pattern as previously where in some cases the timer jobs will fail with either SharePoint Search encountered a problem or a timeout exception.
Here's an example of the GetSearchResults method we use to retrieve the items using IndexDocId.
private ResultTable GetSearchResults(ClientContext cc, KeywordQuery keywordQuery, string startRow, string query, Guid sourceId, List<string> properties) { if (startRow == "0") { keywordQuery.QueryText = query; } else { keywordQuery.QueryText = $"IndexDocId>{startRow} AND ({query})"; } keywordQuery.TrimDuplicates = false; keywordQuery.EnableQueryRules = false; keywordQuery.SourceId = sourceId; keywordQuery.ClientType = "custom"; keywordQuery.EnableSorting = true; keywordQuery.SortList.Add("[DocId]", SortDirection.Ascending); //keywordQuery.SelectProperties.Add("AccountName"); //keywordQuery.SelectProperties.Add("LastName"); keywordQuery.SelectProperties.Add("IndexDocId"); foreach(var property in properties) { keywordQuery.SelectProperties.Add(property); } SearchExecutor searchExec = new SearchExecutor(cc); ClientResult<ResultTableCollection> results = searchExec.ExecuteQuery(keywordQuery); cc.ExecuteQueryRetry(); var resultTable = results.Value.FirstOrDefault(x => x.TableType == KnownTableTypes.RelevantResults); return resultTable; } Here's the stacktrace:
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at XXX.ClientContextExtensions.retry(Action func, Int32 retryCount, Int32 delay) in XXX\ClientContextExtensions.cs:line 278 at XXX.GetSearchResults(ClientContext cc, KeywordQuery keywordQuery, String startRow, String query, Guid sourceId, List`1 properties) in XXX\Managers\SearchManager.cs:line 586 The error messages:
Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.
Timeout
There's a retry pattern in place and if we get throttled this should get logged as warnings, but we don't see any. So, we are quite unsure what is going on - if it's us or it's Microsoft causing these issues?