Is ThreadAbortException to be expected in a HTTP handler on Windows Azure?

asp.net, azure, httphandler

Solution

Whe you upload big files, IIS tries to read request stream and if it blocks for over 5 minutes it would cause IIS to eventually throw ThreadAbortException.

Try playing with this line:

<httpRuntime maxRequestLength="2097150" executionTimeout="3600"/>

Also try these suggestions: http://cutesoft.net/forums/permalink/77440/77438/ShowThread.aspx#77438

Problem

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 `ThreadAbortException` in the handler, most often during a `.Write` to the `Response.OutputStream` (I set `Response.BufferOutput = false` beforehand). The stack trace is as follows: ``` 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) ``` (the `Stream.Write` call is apparently inlined so it does not show in the stack trace). 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? Note that it is a single HTTP handler, not an .aspx/.cshtml page or MVC controller, and nowhere in my code am I touching `Response.End`, `Response.Redirect` or `Server.Transfer`.

Original source