c# - Prevent hung workers in ASP.NET when reading the posted data -


i have issue caused external factor causing app pool queue requests , hang. issue seems caused when client making http request somehow loses tcp layer connection server, whilst server trying read data post'd it.

i using asynchronous http handler, , using following code read posted data:

string post_data = new streamreader(context.request.inputstream).readtoend(); 

i believe happening "readtoend()" blocking worker thread , when tcp layer lost thread stuck there trying read indefinitely. how can prevent happening?

i coding in .net 2.0 can use newer framework if required.

httprequest.inputstream synchronously read entire request, returns stream 1 huge chunk. you'll want instead (requires .net 4.5):

string body = await new streamreader(request.getbufferlessinputstream()).readtoendasync(); 

getbufferlessinputstream() won't read entire request eagerly; returns stream reads request on-demand. readtoendasync() asynchronously read stream without tying worker thread.

to create .net 4.5-style async handler, subclass httptaskasynchandler class. see this blog post more information on async / await in .net 4.5. must target .net 4.5 in web.config functionality.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -