Forum Discussion
SharePoint 429 Error - Throttling
Hi Robert.. yes sure please find below:
for (var i = 0; i < 1000; i++)
{
var lib = ctx.Web.Lists.GetByTitle(libraryName);
var items = lib.GetItems(new CamlQuery());
ctx.Load(items);
try
{
ctx.ExecuteQuery();
}
catch(System.Net.WebException wex)
{
var response = wex.Response as System.Net.HttpWebResponse;
if (response != null && (response.StatusCode == (System.Net.HttpStatusCode)429 || response.StatusCode == (System.Net.HttpStatusCode)503))
{
var retryAfter = Int32.Parse(response.Headers["Retry-After"].ToString());
Thread.Sleep(TimeSpan.FromSeconds(retryAfter));
ctx.ExecuteQuery();
try
{
var x = items.Count; // throws CollectionNotInitializedException
}
catch(Exception ex2)
{
}
}
}
Console.WriteLine($"{i}:{items.Count}");
}
Some comments:
- I wrapping around the ExecuteQuery in a try/catch block and not the ctx.Load() because this suggested that should be enough: https://github.com/SharePoint/PnP/tree/dev/Samples/Core.Throttling
- My idea was to write an ExecuteQueryWithRetry code, similar to the one published by the PnP group but use your retry-after recommendation. This way, all I’d need to change within my code is replacing all calls to ExecuteQuery with ExecuteQueryWithRetry.
- The problem is that the we get an error when accessing the items collection after a retry attempt.
- I guess a “solution” could be to encapsulate the “Load” in the try catch block as well but while this is easy to accomplish in the above code, in our real life scenario it gets much more tricky as there would be a lot of lines of code to modify.
I guess you might be having a lot of calls to ExecuteQuery, I suggest you to try to reduce the calls by loading it them in single context and fire as a single call.
- Feb 13, 2018
We just got hit with this today as well. In my case i simply connected via powershell to enable a cdn and got a 429 back from a single request. I've seen a few posts on this. feels like something changed recently
- Jan GroenenFeb 20, 2018Copper ContributorWe had the same. After converting motlre than 6Tb without any problems using sharegate we were throttled migrating a small delta. Microsoft told us that we were throttled only during business hours. When converting in the weekends and after business hours we did not get the 439 errors anymore!!! Maybe you should try this as well! Good luck!
- Justin SpiteriFeb 21, 2018Copper Contributor
At least you got that reply :)
We have been in contact with Microsoft Support for quiet a while now and we did not get any specific reply like yours :/
However it does not make sense that you are being throttled during business hours for normal use. We have been using this scenario for months (after multiple migrations to SharePoint) and we never had this issue. So I find it very strange that all of a sudden we began to experience this throttling issue.
One item which Microsoft told us was that it could be the case that other tenants could be effecting the overall SharePoint experience, hence effecting other tenants. But again it does not make from a customer perspective.