Skip to content

Commit 8603663

Browse files
Prevent an infinite loop
We have confirmed, that sometimes the exception handling returns a null client wrapper. When this circumstance happens, and it has several times for us, the code goes into an infinite loop because the wrapper remains null and is never set again. Moving the retry attempts increment before the retry (and outside of the exceptions) prevents this infinite loop. Executing the Query as normal when a wrapper is unavailable also ensures a retry is made when the wrapper is null.
1 parent 01e45c8 commit 8603663

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

docs/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,21 @@ public static void ExecuteQueryWithIncrementalRetry(this ClientContext clientCon
202202
}
203203
else
204204
{
205-
// retry the previous request
205+
//increment the retry count
206+
retryAttempts++;
207+
208+
// retry the previous request using wrapper
206209
if (wrapper != null && wrapper.Value != null)
207210
{
208211
clientContext.RetryQuery(wrapper.Value);
209212
return;
210-
}
213+
}
214+
// retry the previous request as normal
215+
else
216+
{
217+
clientContext.ExecuteQuery();
218+
return;
219+
}
211220
}
212221
}
213222
catch (WebException ex)
@@ -237,8 +246,7 @@ public static void ExecuteQueryWithIncrementalRetry(this ClientContext clientCon
237246
// Delay for the requested seconds
238247
Thread.Sleep(retryAfterInterval * 1000);
239248

240-
// Increase counters
241-
retryAttempts++;
249+
// Increase counters
242250
backoffInterval = backoffInterval * 2;
243251
}
244252
else

0 commit comments

Comments
 (0)