fixing The remote host closed the connection. The error code is 0x80070057
Posted on Sep 11, 2009 by Author
I have a particular error that has been haunting me for weeks now. Its nothing too serious. For the affected site, it gets maybe 50 errors / day like this over the course of 35K impressions. But not knowing the cause is pissing me off.
Here is the full error message
System.IO.TextWriter, Boolean, Boolean, System.Web.VirtualPath,
System.Web.VirtualPath, System.String, System.Exception, System.String)
The remote host closed the connection. The error code is 0x80070057.
Error executing child request for photo.aspx.
System.Web.HttpException: The remote host closed the connection. The error code is 0x80070057.
.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpWriter.Write(String s)
at System.Web.UI.HtmlTextWriter.Write(String s)
at ASP.photo_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Investigating the Cause
After looking at my stats Server it would appear that this error happens on pages that people tend to click through very quickly, such as a photo gallery where you are clicking next picture very quickly.
The guys at Eggheadcafe
found the root cause and solution
It has to do with the viewstate not fully loading before moving on to the next page.
Upon inspecting one of the pages on my site that was getting this error I found that the viewstate was taking up more than half of the source code of the page. Over 20K for the viewstate.
What is ViewState?
ViewState is a way for the server to keep track of the values you use for web controls. Its useful for submit forms where you need to submit data on postback, but not for things like Label Controls or Place Holders.
Disable the ViewState on your static web controls like Labels. If the Label's value is not going to change on postback then it should have its viewstate disabled.
<asp:Label ID="mainmenu" runat="server" />
Should look like this
<asp:Label ID="mainmenu" runat="server" EnableViewState="false"/>
Of course this means you need to go through every page in your application and disable the viewstate on every control that requires it.
But if your page doesn't have any controls that need to have viewstate enabled you can just add the attribute to the page directive to disable the viewstate on all controls
So change this
<%@ Page Language="C#" %>
<%@ Page Language="C#" EnableViewState="False" %>
Since implimenting this on one of my larger sites, the errors have almost completely disappeared. It seems the error is caused by slow downs in your asp.net
application. The Viewstate causes additional overhead that does not directly slow down your site per say, but it does greatly increase the size of your pages, which in turn negatively affects your visitors with slower internet connetions ( dial up, Low grade DSL, GPRS ).
However considering the IPs of the users that were having this problem ( some where cable modem ) I thought that there had to be another reason for the slow down. My theory is that the DNS RBL I use that is run by stop forum spam could be under heavy load, and would therefore slow down the DNS RBL lookups, and in turn slow down the page requests. Usually DNS lookups happend extremely fast, but considering my website was pinging their RBL on every application request, this could potentially cause some slow downs. I disabled the code in my global.asax file that was performing the DSL RBL lookup every time Application_BeginRequest was called. Since doing this the errors have almost completely stopped. However I still think there is something else causing this, as I have not heard of anyone else having trouble with Stop Forum Spam's RBL. It seems that if I recycle the App Pool, the errors stop for a period of several hours.
At this point I am not going to claim I have found the direct cause or a solution, but maybe this info might help others who are also dealing with the same situation.
After emailing with a guy from Microsoft. I discovered that what I found on another forum ( to set Buffering to false on the page level ) was incorrect. I removed this statement from my code so it could go back to the default ( Buffering=true ). Since this I haven't received this error once and this was almost a week ago. I think one of the causes was the RBL slowing things down, and the ViewState on my ASP:Label Controls. Remember to disable viewstate on anything that will not need to be preserved on postback..