12

I'm getting a lot of these error messages in my logs on one of my servers and intermittently on two others.

Googling didn't reveal very much information, mostly related to file uploads or downloads being interrupted.

My pages are basically just text files with "ok" in them that only have .aspx extension for future plans, there's no actual code powering the pages. Servers are all Windows Server 2008 RC2 x64 running IIS7 / ASP.NET 4.

Statistically it's happening well under 1% of the time but because of the volume of traffic that still clutters my event log with 2 or 3 of these messages per minute.

Edit: I tracked down the problem, setting buffering to true stopped it occurring.

Ben
  • 416
  • 1
  • 3
  • 12
  • Hi mate, yes the problem was a configuration setting in my web.config's that had buffering set to false. – Ben Oct 15 '10 at 16:30
  • See http://stackoverflow.com/a/22992379/17373 for an example of how to capture this exception and ignore it. – Greg Bray Apr 10 '14 at 15:50
  • Did you read this? [http://blog.whitesites.com/fixing-The-remote-host-closed-the-connection-The-error-code-is-0x80070057__633882307305519259_blog.htm](http://blog.whitesites.com/fixing-The-remote-host-closed-the-connection-The-error-code-is-0x80070057__633882307305519259_blog.htm) – Jeroen Aug 19 '10 at 02:15
  • Yep, and a very long thread at forums.asp.net too. The servers are all identically configured with no viewstate (also no session state) and the pages have no controls or logic anyway. – Ben Aug 19 '10 at 02:18
  • The suggestion in that blog of setting EnableViewState="false" fixed this issue for me. – dgundersen Dec 14 '11 at 19:11

2 Answers2

8

I know this has been answered, but on the off chance this helps someone else, it happened in my MVC project sometimes when I had one dbContext set at the top of a repository. When I switched to a using statement for database connections, the error never appeared again.

So, I went from this at the top of each repository:

DbContext db = new DbContext();

To this for each individual connection:

using (DbContext db = new DbContext())
{
     //db connection stuff here....
}

Worth saying that no one ever reported seeing the error and no error was ever shown to the browser, but nice to get it off the logs all the same!

e-on
  • 1,721
  • 7
  • 30
  • 57
  • 1
    I like this answer because generally you should use the using method anytime you are using external resources (files, web services, basically anything that needs to be closed). This is also cool because it saves you have to write a destructor or dispose method too as it automatically handles this too. – Francis Rodgers Sep 26 '14 at 13:26
4

Are you returning a Stream?

You might need to close it after the method finishes.

Check out this: Closing Returned Streams in WCF

Here is the code this blog suggests:

public Stream GetFile(string path) 
{
   Stream fileStream = null;    

   try   
   {
      fileStream = File.OpenRead(path);
   }
   catch(Exception)
   {
      return null;
   }

   OperationContext clientContext = OperationContext.Current;
   clientContext.OperationCompleted += 
       new EventHandler(delegate(object sender, EventArgs args)
       {
            if (fileStream != null) fileStream.Dispose();
       });
   return fileStream;
}
Nir Kornfeld
  • 827
  • 7
  • 11