Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The remote host closed the connection. The error code is 0x80070057

Tags:

asp.net

iis-7

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.

like image 824
Ben Avatar asked Aug 19 '10 01:08

Ben


2 Answers

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;
}
like image 182
Nir Kornfeld Avatar answered Sep 19 '22 03:09

Nir Kornfeld


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!

like image 44
e-on Avatar answered Sep 17 '22 03:09

e-on