10

Our console applications are making hundreds of WebRequests to Facebook every minute (with using multiple apps and hundreds of access tokens). Now, they started to fail with the exception message in the title ("The request was aborted: The request was canceled"). We searched for hours on the internet, and tried out every possible solution, but nothing helped.

These didn't help:

webRequest.Timeout = 20000; //A request that didn't get respond within 20 seconds is unacceptable, and we would rather just retry.
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.ServicePoint.Expect100Continue = false;

Anyone has any other idea?

edit:

ToString of the Exception: System.Net.WebException: The request was aborted: The request was canceled. ---> System.Net.WebException: The request was canceled at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy, ProxyChain& chain, HttpAbortDelegate& abortDelegate, Int32& abortState) at System.Net.HttpWebRequest.FindServicePoint(Boolean forceFind) at System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception) at System.Net.HttpWebRequest.SetResponse(Exception E) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at WebException message: The request was aborted: The request was canceled.

edit2: And we are NOT reaching the limit. We know when that happens, and the problem is NOT that. We have been doing this for two years, and this thing only happened twice during the whole time. Per AccessToken we are only doing 2-3 requests/minute, and the throttling on Facebook is 600 requests/accesstoken/ip.

edit3: I would like to add an extra tip for people who have this or similar problem: Make sure that you dispose your RequestStream, your Response and your ResponseStream object.

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
Kornél Regius
  • 2,989
  • 5
  • 30
  • 39
  • What did the error message tell you? What have you done to find the reason for the problem? – usr Feb 04 '14 at 09:35
  • 2
    Hundreds of requests to Facebook every minute? You're probably being blocked by Facebook for excessive use. –  Feb 04 '14 at 09:38
  • Mike W -> We are not being blocked. – Kornél Regius Feb 04 '14 at 09:40
  • are there duplicate requests during that time, or do they change from request to request? – Szilard Muzsi Feb 04 '14 at 09:41
  • They change from request to request. – Kornél Regius Feb 04 '14 at 09:41
  • What does Fiddler tell you? – TGlatzer Feb 04 '14 at 09:42
  • 1
    I did not see the error message in the title. Ok that is vague. Please post what Exception.ToString() returns. It includes much more information than this. Also, use Fiddler to look at the full HTTP requests. – usr Feb 04 '14 at 09:42
  • I added the ToString, which does not contain any new information at all. Fiddler does not catch anything. – Kornél Regius Feb 04 '14 at 09:56
  • You have to tell webRequest to use the Proxy fiddler provides. – TGlatzer Feb 04 '14 at 10:00
  • 1
    http://www.dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Net/System/Net/ServicePointManager@cs/1305376/ServicePointManager@cs I can see where the exception is thrown. Did you try increasing the HTTP request limit? The default is 2 per seconds. `ServicePointManager.DefaultConnectionLimit = 1000;` – usr Feb 04 '14 at 10:12
  • usr, please make your comment into an answer. It worked. – Kornél Regius Feb 04 '14 at 10:23

2 Answers2

13

http://www.dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Net/System/Net/ServicePointManager@cs/1305376/ServicePointManager@cs

I can see where the exception is thrown. Did you try increasing the HTTP request limit? The default is 2 per seconds.

ServicePointManager.DefaultConnectionLimit = 1000;
usr
  • 168,620
  • 35
  • 240
  • 369
  • Thank you. I knew that the problem was not the Facebook limit. – Kornél Regius Feb 04 '14 at 10:32
  • Yes, the Facebook limit would have resulted in a different error message. Probably a status 500 + some message. There was no evidence for that. – usr Feb 04 '14 at 10:41
  • The limit reach results this message: "Calls to stream have exceeded the rate of 600 calls per 600 seconds" (We are using FQL) – Kornél Regius Feb 04 '14 at 10:48
  • The link in the answer no longer works. – Turbo Mar 16 '22 at 08:37
  • @Turbo Thanks for letting me know. This issue seems quite obsolete. Are you still interested in this? – usr Mar 16 '22 at 10:45
  • @usr I am still seeing this error. But I was able to try out the suggestion anyways, so I am ok without the link. – Turbo Mar 17 '22 at 18:58
0

My Solve for Xamarin

public async Task<string> GetMessageEx(HttpWebResponse response)
{
    Stream streamResponse = response.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    string result = await streamRead.ReadToEndAsync();
    await streamResponse.FlushAsync();
    return result;
}
pjpscriv
  • 866
  • 11
  • 20
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '22 at 07:35