[Mono-aspnet-list] HttpWebRequest Allocates Multiple Threads per Request

Sean Reque sean.reque at ni.com
Mon Jan 21 17:56:12 UTC 2013


Hi, Robert.

Thanks for the response.

My problem is that for our application, we've ran into problems with 
standard library functions using the global thread pool, where eventually 
threads in our application would hang indefinitely. We saw this when using 
the Begin* I/O functions on System.Diagnostics.Process objects. As soon as 
we switched to managing our own threads and using the synchronous methods, 
our application no longer hung.

I am unfortunately again seeing hangs when switching from using a web 
client based on curl and native code to System.Net.WebRequest.. Further 
investigation revealed that we are inadvertently once again using 
asynchronous I/O operations. I'm not an expert on the subject, but I poked 
around mcs/class/System/System.Net/HttpWebRequest.cs and the code does not 
look exception safe to me. There are several places where monitors are 
entered and methods subsequently called without a try/catch block, so that 
if any of them threw, a deadlock would seem likely to occur.

I think our solutions for now are going to have to be 
        1. Continue to rely on native code for web requests.
        2. Investigate writing our own simple library for doing web 
requests.
        3. Investigate using a java web client library through IKVM, such 
as Apache HttpClient.

  Sean



From:   Robert Jordan <robertj at gmx.net>
To:     mono-aspnet-list at lists.ximian.com, 
Date:   01/21/2013 11:39 AM
Subject:        Re: [Mono-aspnet-list] HttpWebRequest Allocates Multiple 
Threads per Request
Sent by:        mono-aspnet-list-bounces at lists.ximian.com



On 21.01.2013 17:11, Sean Reque wrote:
> I noticed today in a debugger session that  performing a simple POST
> request with HttpWebRequest  allocates three new threads. Examining the
> source code reveals that the synchronous methods GetRequestStream() and
> GetResponseStream() use the asynchronous versions of themselves 
underneath
> the hood.
> Allocating three threads per request is unacceptable for my application.
> Is there any way to work around this so that making synchronous requests
> does not allocate new threads?

The threads you're seeing belong to the thread & I/O pools. They
are allocated once and then reused. There is no way to disable
this behavior.

Robert



_______________________________________________
Mono-aspnet-list mailing list
Mono-aspnet-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-aspnet-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20130121/f01e3469/attachment.html>


More information about the Mono-aspnet-list mailing list