Hit or Miss forcibly closed WHY?!?!?

Jan 27, 2010 at 11:59 PM

Just finished up my app with 3.0 but I keep randomly getting "An existing connection was forcibly closed by the remote host". What is going on with this? It is very frustrating.

Jan 28, 2010 at 2:57 PM

I had 100's of these exceptions logged yesterday about the time of your post.  Facebook had a problem.  See here http://developers.facebook.com/live_status.php and signup to subscribe to notifications.  I think these errors are just something you have to expect with Facebook.

Jan 28, 2010 at 4:04 PM

This is still happening for me, and it doesn't seem to be a facebook problem as on other websites I can login with fbconnect just fine... Anyone has a solution?

Jan 29, 2010 at 12:25 AM
Edited Jan 29, 2010 at 1:25 PM

This has been an issue for some time now.  I started really seeing it repeatedly the past few days though.  I made some changes to the RestBase.cs file to retry.  I realize this can potentially put you in an infinite loop constantly retrying.  I'm planning to add some code to limit the retries when I get time.  At the moment I'd rather spend time getting events.invite added.

internal static WebResponse postRequest(string requestUrl, string postString, bool compressHttp)


                var webRequest = WebRequest.Create(requestUrl);
                webRequest.Method = "POST";
                webRequest.ContentType = "application/x-www-form-urlencoded";

                if (compressHttp)
                    webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");

                if (!String.IsNullOrEmpty(postString))
                    var parameterString = Encoding.UTF8.GetBytes(postString);
                    webRequest.ContentLength = parameterString.Length;

                    using (var buffer = webRequest.GetRequestStream())
                        buffer.Write(parameterString, 0, parameterString.Length);

                return webRequest.GetResponse();


            catch (Exception e)
                if (e.Message.Contains("connection") || e.Message.Contains("closed"))
                    return postRequest(requestUrl, postString, compressHttp);
                    throw e;







Jan 29, 2010 at 12:05 PM
Edited Jan 29, 2010 at 12:16 PM

Is there a dispose or cleanup options for toolkit calls that I may be missing in my code? Like disposing of your datatable connections when your done with em?  I noticed if I reset my IIS or simply overwrote the facebook.dll and facebookweb.dll files, it started working again.

 So instead of: (Sorry for the vb to all the C# folks)
dim fbUser as string = MyBase.Api.Users.GetInfo().uid

Should I be doing something like this instead:
dim fbUser as string
dim apiUsers as MyBase.Api.Users
fbUsers = apiUsers.GetInfo().uid


Jan 29, 2010 at 1:20 PM

Cleaning up your objects is always good coding practice.  In the case of the API there is no Dispose.  In cases where a class has no Dispose for cleanup set the object = nothing.  So fbUsers = Nothing in your example.

The root of the problem is on the Facebook side not the toolkit.  This is a well documented issue for .Net and PHP Facebook developers alike.  I've even seen posts about this happening in large iPhone applications using the iPhone FB Connect XCode.  Facebook is having a lot of growth / latency issues lately.  Check out http://developers.facebook.com/live_status.php for current status.  You can see all the API / Performance issues they've been posting about over the past few days.  

The only way to resolve this on your end is simply to retry the call until it works.  I just decided to do it in on the library side instead of wrapping every FB call in my code in Try/Catch/Retry blocks.  Nothing else you can do at this point.  My code above checks for "connection" and "closed" in the exception message and only retries in those cases.  There are at least 3 different exception messages that I've found so far.  Checking for connection and closed covers them all.