title: Is ThreadAbortException to be expected in a HTTP handler on Windows Azure?
body: <p>I have an ASP.NET HTTP handler hosted on Windows Azure in a "small" compute instance. It handles downloads and uploads of large binary files. Nothing else runs within that web role, and there are 2 instances configured, as per guidelines. When a download is done from a computer with a slow connection and I try to perform several downloads at once to choke the bandwidth on the client side, sometimes I get a <code>ThreadAbortException</code> in the handler, most often during a <code>.Write</code> to the <code>Response.OutputStream</code> (I set <code>Response.BufferOutput = false</code> beforehand). The stack trace is as follows:</p>
  
  <pre><code>System.Threading.ThreadAbortException: Thread was being aborted.
     at System.Web.Hosting.UnsafeIISMethods.MgdExplicitFlush(IntPtr context)
     at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
     at System.Web.HttpResponse.Flush(Boolean finalFlush)
     at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
     at MyHandler.ProcessGetRequest(HttpContext context)
     at MyHandler.ProcessRequest(HttpContext context)
  </code></pre>
  
  <p>(the <code>Stream.Write</code> call is apparently inlined so it does not show in the stack trace).</p>
  
  <p>Why is the thread being aborted? I am guessing I am hitting some kind of a timeout (possibly a socket write timeout), is aborting the thread a normal way for the ASP.NET runtime to handle it?</p>
  
  <p>Note that it is a single HTTP handler, not an .aspx/.cshtml page or MVC controller, and nowhere in my code am I touching <code>Response.End</code>, <code>Response.Redirect</code> or <code>Server.Transfer</code>.</p>