The request was aborted: The request was canceled. No solution works
Asked Answered
C

2

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.

Coven answered 4/2, 2014 at 9:34 Comment(11)
What did the error message tell you? What have you done to find the reason for the problem?Alvinaalvine
Hundreds of requests to Facebook every minute? You're probably being blocked by Facebook for excessive use.Eudy
Mike W -> We are not being blocked.Ottilie
are there duplicate requests during that time, or do they change from request to request?Boland
They change from request to request.Ottilie
What does Fiddler tell you?Aluminiferous
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.Alvinaalvine
I added the ToString, which does not contain any new information at all. Fiddler does not catch anything.Ottilie
You have to tell webRequest to use the Proxy fiddler provides.Aluminiferous
dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/… 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;Alvinaalvine
usr, please make your comment into an answer. It worked.Ottilie
A
15

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;
Alvinaalvine answered 4/2, 2014 at 10:31 Comment(6)
Thank you. I knew that the problem was not the Facebook limit.Ottilie
Yes, the Facebook limit would have resulted in a different error message. Probably a status 500 + some message. There was no evidence for that.Alvinaalvine
The limit reach results this message: "Calls to stream have exceeded the rate of 600 calls per 600 seconds" (We are using FQL)Ottilie
The link in the answer no longer works.Sphinx
@Sphinx Thanks for letting me know. This issue seems quite obsolete. Are you still interested in this?Alvinaalvine
@Alvinaalvine I am still seeing this error. But I was able to try out the suggestion anyways, so I am ok without the link.Sphinx
A
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;
}
Aviate answered 5/1, 2022 at 7:30 Comment(1)
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.Pummel

© 2022 - 2024 — McMap. All rights reserved.